JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> value for the variable, which can be null */ public void declareVariable(String varName, Object value) { vars.put(varName, value); } /** * Removes an existing variable. May throw UnsupportedOperationException. * * @param varName is a variable name without the "$" sign */ public void undeclareVariable(String varName) { vars.remove(varName); } public String toString() { return vars.toString(); } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> { return true; } public QName getName() { return name; } public Object getBaseValue() { if (!actual) { throw new JXPathException("Undefined variable: " + name); } return variables.getVariable(name.toString()); } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public boolean isCollection() { Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); } public Object getImmediateNode() { Object value = getBaseValue(); return index == WHOLE_COLLECTION ? ValueUtils.getValue(value) : ValueUtils.getValue(value, index); } public void setValue(Object value) { if (!actual) { throw new JXPathException("Cannot set undefined variable: " + name); } valuePointer = null; if (index != WHOLE_COLLECTION) { Object collection = getBaseValue(); ValueUtils.setValue(collection, index, value); } else { variables.declareVariable(name.toString(), value); } } public boolean isActual() { return actual; } public void setIndex(int index) { super.setIndex(index); valuePointer = null; } public NodePointer getImmediateValuePointer() { if (valuePointer == null) { Object value = null; if (actual) { value = getImmediateNode(); valuePointer = NodePointer.newChildNodePointer(this, null, value); } else { return new NullPointer(this, getName()) { public Object getImmediateNode() { throw new JXPathException( "Undefined variable: " + name); } }; } } return valuePointer; } public int getLength() { if (actual) { Object value = getBaseValue(); return value == null ? 1 : ValueUtils.getLength(value); } return 0; } public NodePointer createPath(JXPathContext context, Object value) { if (actual) { setValue(value); return this; } NodePointer ptr = createPath(context);

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> ptr.setValue(value); return ptr; } public NodePointer createPath(JXPathContext context) { if (!actual) { AbstractFactory factory = getAbstractFactory(context); if (!factory.declareVariable(context, name.toString())) { throw new JXPathAbstractFactoryException( "Factory cannot define variable '" + name + "' for path: " + asPath()); } findVariables(context); // Assert: actual == true } return this; } public NodePointer createChild( JXPathContext context, QName name, int index) { Object collection = createCollection(context, index); if (!isActual() || (index != 0 && index != WHOLE_COLLECTION)) { AbstractFactory factory = getAbstractFactory(context); boolean success = factory.createObject( context, this, collection, getName().toString(), index); if (!success) { throw new JXPathAbstractFactoryException( "Factory could not create object path: " + asPath()); } NodePointer cln = (NodePointer) clone(); cln.setIndex(index); return cln; } return this; } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { Object collection = createCollection(context, index); ValueUtils.setValue(collection, index, value); NodePointer cl = (NodePointer) clone(); cl.setIndex(index); return cl; } private Object createCollection(JXPathContext context, int index) { createPath(context); Object collection = getBaseValue(); if (collection == null) { throw new JXPathAbstractFactoryException( "Factory did not assign a collection to variable '" + name + "' for path: " + asPath()); } if (index == WHOLE_COLLECTION) { index = 0; } else if (index < 0) { throw new JXPathInvalidAccessException("Index is less than 1: " + asPath()); } if (index >= getLength()) { collection = ValueUtils.expandCollection(collection, index + 1); variables.declareVariable(name.toString(), collection); }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> true; } public void setValue(Object value) { if (parent == null || parent.isContainer()) { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", the target object is null"); } if (parent instanceof PropertyOwnerPointer && ((PropertyOwnerPointer) parent). isDynamicPropertyDeclarationSupported()){ // If the parent property owner can create // a property automatically - let it do so PropertyPointer propertyPointer = ((PropertyOwnerPointer) parent).getPropertyPointer(); propertyPointer.setPropertyName(propertyName); propertyPointer.setValue(value); } else { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", path does not match a changeable location"); } } public NodePointer createPath(JXPathContext context) { NodePointer newParent = parent.createPath(context); if (isAttribute()) { return newParent.createAttribute(context, getName()); } if (parent instanceof NullPointer && parent.equals(newParent)) { throw createBadFactoryException(context.getFactory()); } // Consider these two use cases: // 1. The parent pointer of NullPropertyPointer is // a PropertyOwnerPointer other than NullPointer. When we call // createPath on it, it most likely returns itself. We then // take a PropertyPointer from it and get the PropertyPointer // to expand the collection for the corresponding property. // // 2. The parent pointer of NullPropertyPointer is a NullPointer. // When we call createPath, it may return a PropertyOwnerPointer // or it may return anything else, like a DOMNodePointer. // In the former case we need to do exactly what we did in use // case 1. In the latter case, we simply request that the // non-property pointer expand the collection by itself. if (newParent instanceof PropertyOwnerPointer) { PropertyOwnerPointer pop = (PropertyOwnerPointer) newParent; newParent = pop.getPropertyPointer(); } return newParent.createChild(context, getName(), getIndex()); } public NodePointer createPath(JXPathContext context, Object value) { NodePointer newParent = parent.createPath(context);

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> if (isAttribute()) { NodePointer pointer = newParent.createAttribute(context, getName()); pointer.setValue(value); return pointer; } if (parent instanceof NullPointer && parent.equals(newParent)) { throw createBadFactoryException(context.getFactory()); } if (newParent instanceof PropertyOwnerPointer) { PropertyOwnerPointer pop = (PropertyOwnerPointer) newParent; newParent = pop.getPropertyPointer(); } return newParent.createChild(context, getName(), index, value); } public NodePointer createChild( JXPathContext context, QName name, int index) { return createPath(context).createChild(context, name, index); } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { return createPath(context).createChild(context, name, index, value); } public String getPropertyName() { return propertyName; } public void setPropertyName(String propertyName) { this.propertyName = propertyName; } public void setNameAttributeValue(String attributeValue) { this.propertyName = attributeValue; byNameAttribute = true; } public boolean isCollection() { return getIndex() != WHOLE_COLLECTION; } public int getPropertyCount() { return 0; } public String[] getPropertyNames() { return new String[0]; } public String asPath() { if (!byNameAttribute) { return super.asPath(); } StringBuffer buffer = new StringBuffer(); buffer.append(getImmediateParentPointer().asPath()); buffer.append("[@name='"); buffer.append(escape(getPropertyName())); buffer.append("']"); if (index != WHOLE_COLLECTION) { buffer.append('[').append(index + 1).append(']'); } return buffer.toString(); } private String escape(String string) { int index = string.indexOf('\''); while (index != -1) { string = string.substring(0, index) + "&apos;" + string.substring(index + 1); index = string.indexOf('\''); } index = string.indexOf('\"'); while (index !=

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> which have no properties of their own. */ public boolean isAtomic() { return atomic; } /** * Return true if the corresponding objects have dynamic properties. */ public boolean isDynamic() { return dynamicPropertyHandlerClass != null; } public synchronized PropertyDescriptor[] getPropertyDescriptors() { if (propertyDescriptors == null) { try { BeanInfo bi = null; if (clazz.isInterface()) { bi = Introspector.getBeanInfo(clazz); } else { bi = Introspector.getBeanInfo(clazz, Object.class); } PropertyDescriptor[] pds = bi.getPropertyDescriptors(); PropertyDescriptor[] descriptors = new PropertyDescriptor[pds.length]; System.arraycopy(pds, 0, descriptors, 0, pds.length); Arrays.sort(descriptors, new Comparator() { public int compare(Object left, Object right) { return ((PropertyDescriptor) left).getName().compareTo( ((PropertyDescriptor) right).getName()); } }); propertyDescriptors = descriptors; } catch (IntrospectionException ex) { ex.printStackTrace(); } } return propertyDescriptors; } public synchronized PropertyDescriptor getPropertyDescriptor(String propertyName) { if (propertyDescriptorMap == null) { propertyDescriptorMap = new HashMap(); PropertyDescriptor[] pds = getPropertyDescriptors(); for (int i = 0; i < pds.length; i++) { propertyDescriptorMap.put(pds[i].getName(), pds[i]); } } return (PropertyDescriptor) propertyDescriptorMap.get(propertyName); } /** * For a dynamic class, returns the corresponding DynamicPropertyHandler * class. */ public Class getDynamicPropertyHandlerClass() { return dynamicPropertyHandlerClass; } public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("BeanInfo [class = "); buffer.append(clazz.getName()); if (isDynamic()) { buffer.append(", dynamic"); } if (isAtomic()) { buffer.append(", atomic"); } buffer.append(", properties = "); PropertyDescriptor[] jpds = getPropertyDescriptors(); for (int i = 0; i < jpds.length; i++) { buffer.append("\n ");

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.text.DecimalFormatSymbols; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; import org.apache.commons.jxpath.util.KeyManagerUtils; /** * JXPathContext provides APIs for the traversal of graphs of JavaBeans using * the XPath syntax. Using JXPathContext, you can read and write properties of * JavaBeans, arrays, collections and maps. JXPathContext uses JavaBeans * introspection to enumerate and access JavaBeans properties. * <p> * JXPathContext allows alternative implementations. This is why instead of * allocating JXPathContext directly, you should call a static * <code>newContext</code> method. This method will utilize the * JXPathContextFactory API to locate a suitable implementation of JXPath. * Bundled with JXPath comes a default implementation called Reference * Implementation. * </p> * * <h2>JXPath Interprets XPath Syntax on Java Object Graphs</h2> * * JXPath uses an intuitive interpretation of the xpath syntax in the context * of Java object graphs. Here are some examples: * * <h3>Example 1: JavaBean Property Access</h3> * * JXPath can be used to access properties of a JavaBean. * * <

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> } return compilationContext.compilePath(xpath); } /** * Overridden by each concrete implementation of JXPathContext * to perform compilation. Is called by <code>compile()</code>. */ protected abstract CompiledExpression compilePath(String xpath); /** * Finds the first object that matches the specified XPath. It is equivalent * to <code>getPointer(xpath).getNode()</code>. Note that this method * produces the same result as <code>getValue()</code> on object models * like JavaBeans, but a different result for DOM/JDOM etc., because it * returns the Node itself, rather than its textual contents. * * @param xpath the xpath to be evaluated * @return the found object */ public Object selectSingleNode(String xpath) { Pointer pointer = getPointer(xpath); return pointer == null ? null : pointer.getNode(); } /** * Finds all nodes that match the specified XPath. * * @param xpath the xpath to be evaluated * @return a list of found objects */ public List selectNodes(String xpath) { ArrayList list = new ArrayList(); Iterator iterator = iteratePointers(xpath); while (iterator.hasNext()) { Pointer pointer = (Pointer) iterator.next(); list.add(pointer.getNode()); } return list; } /** * Evaluates the xpath and returns the resulting object. Primitive * types are wrapped into objects. */ public abstract Object getValue(String xpath); /** * Evaluates the xpath, converts the result to the specified class and * returns the resulting object. */ public abstract Object getValue(String xpath, Class requiredType); /** * Modifies the value of the property described by the supplied xpath. * Will throw an exception if one of the following conditions occurs: * <ul> * <li>The xpath does not in fact describe an existing property * <li>The property is not writable (no public, non-static set method) * </ul> */ public abstract void setValue(String xpath, Object value); /** * Creates missing elements of the path by invoking an AbstractFactory, * which should first be installed on the context by calling "setFactory". * <p> * Will

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> throw an exception if the AbstractFactory fails to create * an instance for a path element. */ public abstract Pointer createPath(String xpath); /** * The same as setValue, except it creates intermediate elements of * the path by invoking an AbstractFactory, which should first be * installed on the context by calling "setFactory". * <p> * Will throw an exception if one of the following conditions occurs: * <ul> * <li>Elements of the xpath aleady exist, but the path does not in * fact describe an existing property * <li>The AbstractFactory fails to create an instance for an intermediate * element. * <li>The property is not writable (no public, non-static set method) * </ul> */ public abstract Pointer createPathAndSetValue(String xpath, Object value); /** * Removes the element of the object graph described by the xpath. */ public abstract void removePath(String xpath); /** * Removes all elements of the object graph described by the xpath. */ public abstract void removeAll(String xpath); /** * Traverses the xpath and returns an Iterator of all results found * for the path. If the xpath matches no properties * in the graph, the Iterator will be empty, but not null. */ public abstract Iterator iterate(String xpath); /** * Traverses the xpath and returns a Pointer. * A Pointer provides easy access to a property. * If the xpath matches no properties * in the graph, the pointer will be null. */ public abstract Pointer getPointer(String xpath); /** * Traverses the xpath and returns an Iterator of Pointers. * A Pointer provides easy access to a property. * If the xpath matches no properties * in the graph, the Iterator be empty, but not null. */ public abstract Iterator iteratePointers(String xpath); /** * Install an identity manager that will be used by the context * to look up a node by its ID. */ public void setIdentityManager(IdentityManager idManager) { this.idManager = idManager; } /** * Returns this context's identity manager. If none has been installed, * returns the identity manager of the parent context. */ public IdentityManager getIdentityManager() {

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> if (idManager == null && parentContext != null) { return parentContext.getIdentityManager(); } return idManager; } /** * Locates a Node by its ID. * * @param id is the ID of the sought node. */ public Pointer getPointerByID(String id) { IdentityManager manager = getIdentityManager(); if (manager != null) { return manager.getPointerByID(this, id); } throw new JXPathException( "Cannot find an element by ID - " + "no IdentityManager has been specified"); } /** * Install a key manager that will be used by the context * to look up a node by a key value. */ public void setKeyManager(KeyManager keyManager) { this.keyManager = keyManager; } /** * Returns this context's key manager. If none has been installed, * returns the key manager of the parent context. */ public KeyManager getKeyManager() { if (keyManager == null && parentContext != null) { return parentContext.getKeyManager(); } return keyManager; } /** * Locates a Node by a key value. */ public Pointer getPointerByKey(String key, String value) { KeyManager manager = getKeyManager(); if (manager != null) { return manager.getPointerByKey(this, key, value); } throw new JXPathException( "Cannot find an element by key - " + "no KeyManager has been specified"); } /** * Locates a NodeSet by key/value. * @param key * @param value */ public NodeSet getNodeSetByKey(String key, Object value) { KeyManager manager = getKeyManager(); if (manager != null) { return KeyManagerUtils.getExtendedKeyManager(manager) .getNodeSetByKey(this, key, value); } throw new JXPathException("Cannot find an element by key - " + "no KeyManager has been specified"); } /** * Registers a namespace prefix. * * @param prefix A namespace prefix * @param namespaceURI A URI for that prefix */ public void registerNamespace(String prefix, String namespaceURI) { throw new UnsupportedOperationException( "

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> public static final int FUNCTION_STRING_LENGTH = 15; public static final int FUNCTION_NORMALIZE_SPACE = 16; public static final int FUNCTION_TRANSLATE = 17; public static final int FUNCTION_BOOLEAN = 18; public static final int FUNCTION_NOT = 19; public static final int FUNCTION_TRUE = 20; public static final int FUNCTION_FALSE = 21; public static final int FUNCTION_LANG = 22; public static final int FUNCTION_NUMBER = 23; public static final int FUNCTION_SUM = 24; public static final int FUNCTION_FLOOR = 25; public static final int FUNCTION_CEILING = 26; public static final int FUNCTION_ROUND = 27; public static final int FUNCTION_NULL = 28; public static final int FUNCTION_KEY = 29; public static final int FUNCTION_FORMAT_NUMBER = 30; /** * Produces an EXPRESSION object that represents a numeric constant. */ Object number(String value); /** * Produces an EXPRESSION object that represents a string constant. */ Object literal(String value); /** * Produces an QNAME that represents a name with an optional prefix. */ Object qname(String prefix, String name); /** * Produces an EXPRESSION object representing the sum of all argumens * * @param arguments are EXPRESSION objects */ Object sum(Object[] arguments); /** * Produces an EXPRESSION object representing <i>left</i> minus <i>right</i> * * @param left is an EXPRESSION object * @param right is an EXPRESSION object */ Object minus(Object left, Object right); /** * Produces an EXPRESSION object representing <i>left</i> multiplied by * <i>right</i> * * @param left is an EXPRESSION object * @param right is an EXPRESSION object */ Object multiply(Object left, Object right); /** * Produces an EXPRESSION object representing <i>left</i> divided by * <i>right</i> * * @param left is an EXPRESSION object * @param

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> right is an EXPRESSION object */ Object divide(Object left, Object right); /** * Produces an EXPRESSION object representing <i>left</i> modulo * <i>right</i> * * @param left is an EXPRESSION object * @param right is an EXPRESSION object */ Object mod(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * <i>left</i> less than <i>right</i> * * @param left is an EXPRESSION object * @param right is an EXPRESSION object */ Object lessThan(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * <i>left</i> less than or equal to <i>right</i> * * @param left is an EXPRESSION object * @param right is an EXPRESSION object */ Object lessThanOrEqual(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * <i>left</i> greater than <i>right</i> * * @param left is an EXPRESSION object * @param right is an EXPRESSION object */ Object greaterThan(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * <i>left</i> greater than or equal to <i>right</i> * * @param left is an EXPRESSION object * @param right is an EXPRESSION object */ Object greaterThanOrEqual(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * <i>left</i> equals to <i>right</i> * * @param left is an EXPRESSION object * @param right is an EXPRESSION object */ Object equal(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * <i>left</i> is not equal to <i>right</i> * * @param left is an EXPRESSION object * @param right is an EXPRESSION object */ Object notEqual(Object left, Object right); /** * Produces an EXPRESSION object representing unary negation of the argument

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>) { if (debug) { System.err.println( "JXPath: found java.home property " + factory); } return factory; } } } catch (Exception ex) { if (debug) { ex.printStackTrace(); } } String serviceId = "META-INF/services/" + property; // try to find services in CLASSPATH try { ClassLoader cl = JXPathContextFactory.class.getClassLoader(); InputStream is = null; if (cl == null) { is = ClassLoader.getSystemResourceAsStream(serviceId); } else { is = cl.getResourceAsStream(serviceId); } if (is != null) { if (debug) { System.err.println("JXPath: found " + serviceId); } BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String factory = rd.readLine(); rd.close(); if (factory != null && !"".equals(factory)) { if (debug) { System.err.println( "JXPath: loaded from services: " + factory); } return factory; } } } catch (Exception ex) { if (debug) { ex.printStackTrace(); } } return defaultFactory; } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> in the case of an XML element, getValue() will * return the text contained by the element rather than * the element itself. */ Object getValue(); /** * Returns the raw value of the object, property or collection element * this pointer represents. Never converts the object to a * canonical type: returns it as is. * * For example, for an XML element, getNode() will * return the element itself rather than the text it contains. */ Object getNode(); /** * Modifies the value of the object, property or collection element * this pointer represents. */ void setValue(Object value); /** * Returns the node this pointer is based on. */ Object getRootNode(); /** * Returns a string that is a proper "canonical" XPath that corresponds to * this pointer. Consider this example: * <p><code>Pointer ptr = ctx.getPointer("//employees[firstName = 'John']") * </code> * <p>The value of <code>ptr.asPath()</code> will look something like * <code>"/departments[2]/employees[3]"</code>, so, basically, it represents * the concrete location(s) of the result of a search performed by JXPath. * If an object in the pointer's path is a Dynamic Property object (like a * Map), the asPath method generates an XPath that looks like this: <code>" * /departments[@name = 'HR']/employees[3]"</code>. */ String asPath(); /** * Pointers are cloneable */ Object clone(); }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> resolve relative URIs to absolute ones. return defaultNamespace.equals("") ? null : defaultNamespace; } public Object getBaseValue() { return node; } public Object getImmediateNode() { return node; } public boolean isActual() { return true; } public boolean isCollection() { return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } protected static String findEnclosingAttribute(Node n, String attrName) { while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; String attr = e.getAttribute(attrName); if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } protected String getLanguage() { return findEnclosingAttribute(node, "xml:lang"); } /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); } else { node.getParentNode().removeChild(node); } } else { NodeList children = node.getChildNodes(); int count =

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> children.getLength(); for (int i = count; --i >= 0;) { Node child = children.item(i); node.removeChild(child); } if (value instanceof Node) { Node valueNode = (Node) value; if (valueNode instanceof Element || valueNode instanceof Document) { children = valueNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); node.appendChild(child.cloneNode(true)); } } else { node.appendChild(valueNode.cloneNode(true)); } } else { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { Node textNode = node.getOwnerDocument().createTextNode(string); node.appendChild(textNode); } } } } public NodePointer createChild( JXPathContext context, QName name, int index) { if (index == WHOLE_COLLECTION) { index = 0; } boolean success = getAbstractFactory(context).createObject( context, this, node, name.toString(), index); if (success) { NodeTest nodeTest; String prefix = name.getPrefix(); String namespaceURI = prefix == null ? null : context.getNamespaceURI(prefix); nodeTest = new NodeNameTest(name, namespaceURI); NodeIterator it = childIterator(nodeTest, false, null); if (it != null && it.setPosition(index + 1)) { return it.getNodePointer(); } } throw new JXPathAbstractFactoryException( "Factory could not create a child node for path: " + asPath() + "/" + name + "[" + (index + 1) + "]"); } public NodePointer createChild(JXPathContext context, QName name, int index, Object value) { NodePointer ptr = createChild(context, name, index); ptr.setValue(value); return ptr; } public NodePointer createAttribute(JXPathContext context, QName name) { if (!(node instanceof Element)) { return super.createAttribute(context,

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> name); } Element element = (Element) node; String prefix = name.getPrefix(); if (prefix != null) { String ns = getNamespaceURI(prefix); if (ns == null) { throw new JXPathException( "Unknown namespace prefix: " + prefix); } element.setAttributeNS(ns, name.toString(), ""); } else { if (!element.hasAttribute(name.getName())) { element.setAttribute(name.getName(), ""); } } NodeIterator it = attributeIterator(name); it.setPosition(1); return it.getNodePointer(); } public void remove() { Node parent = node.getParentNode(); if (parent == null) { throw new JXPathException("Cannot remove root DOM node"); } parent.removeChild(node); } public String asPath() { if (id != null) { return "id('" + escape(id) + "')"; } StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); } switch (node.getNodeType()) { case Node.ELEMENT_NODE : // If the parent pointer is not a DOMNodePointer, it is // the parent's responsibility to produce the node test part // of the path if (parent instanceof DOMNodePointer) { if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } String ln = DOMNodePointer.getLocalName(node); String nsURI = getNamespaceURI(); if (nsURI == null) { buffer.append(ln); buffer.append('['); buffer.append(getRelativePositionByName()).append(']'); } else { String prefix = getNamespaceResolver().getPrefix(nsURI); if (prefix != null) { buffer.append(prefix); buffer.append(':'); buffer.append(ln); buffer.append('['); buffer.append(getRelativePositionByName()); buffer.append(']'); } else { buffer.append("node()"); buffer.append('['); buffer.append(getRelativePositionOfElement()); buffer.append(']'); } } } break;

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>) { count++; } n = n.getPreviousSibling(); } return count; } private int getRelativePositionOfPI(String target) { int count = 1; Node n = node.getPreviousSibling(); while (n != null) { if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE && ((ProcessingInstruction) n).getTarget().equals(target)) { count++; } n = n.getPreviousSibling(); } return count; } public int hashCode() { return System.identityHashCode(node); } public boolean equals(Object object) { return object == this || object instanceof DOMNodePointer && node == ((DOMNodePointer) object).node; } public static String getPrefix(Node node) { String prefix = node.getPrefix(); if (prefix != null) { return prefix; } String name = node.getNodeName(); int index = name.lastIndexOf(':'); return index < 0 ? null : name.substring(0, index); } public static String getLocalName(Node node) { String localName = node.getLocalName(); if (localName != null) { return localName; } String name = node.getNodeName(); int index = name.lastIndexOf(':'); return index < 0 ? name : name.substring(index + 1); } public static String getNamespaceURI(Node node) { if (node instanceof Document) { node = ((Document) node).getDocumentElement(); } Element element = (Element) node; String uri = element.getNamespaceURI(); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } return null; } public Object getValue() { if (node.getNodeType() ==

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> Node.COMMENT_NODE) { String text = ((Comment) node).getData(); return text == null ? "" : text.trim(); } return stringValue(node); } private String stringValue(Node node) { int nodeType = node.getNodeType(); if (nodeType == Node.COMMENT_NODE) { return ""; } boolean trim = !"preserve".equals(findEnclosingAttribute(node, "xml:space")); if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { String text = node.getNodeValue(); return text == null ? "" : trim ? text.trim() : text; } if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) { String text = ((ProcessingInstruction) node).getData(); return text == null ? "" : trim ? text.trim() : text; } NodeList list = node.getChildNodes(); StringBuffer buf = new StringBuffer(16); for (int i = 0; i < list.getLength(); i++) { Node child = list.item(i); buf.append(stringValue(child)); } return buf.toString(); } /** * Locates a node by ID. */ public Pointer getPointerByID(JXPathContext context, String id) { Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument(); Element element = document.getElementById(id); return element == null ? (Pointer) new NullPointer(getLocale(), id) : new DOMNodePointer(element, getLocale(), id); } private AbstractFactory getAbstractFactory(JXPathContext context) { AbstractFactory factory = context.getFactory(); if (factory == null) { throw new JXPathException( "Factory is not set on the JXPathContext - " + "cannot create path: " + asPath()); } return factory; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { Node node1 = (Node) pointer1.getBaseValue(); Node node2 = (Node) pointer2.getBaseValue(); if (node1 == node2) { return 0; } int t1 = node

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.axes.InitialContext; /** * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class LocationPath extends Path { private boolean absolute; public LocationPath(boolean absolute, Step[] steps) { super(steps); this.absolute = absolute; } public boolean isAbsolute() { return absolute; } public boolean computeContextDependent() { return !absolute || super.computeContextDependent(); } public String toString() { StringBuffer buffer = new StringBuffer(); Step steps[] = getSteps(); if (steps != null) { for (int i = 0; i < steps.length; i++) { if (i > 0 || absolute) { buffer.append('/'); } buffer.append(steps[i]); } } return buffer.toString(); } public Object compute(EvalContext context) { // Create a chain of contexts EvalContext rootContext; if (isAbsolute()) { rootContext = context.getRootContext().getAbsoluteRootContext(); } else { rootContext = new InitialContext(context); } return evalSteps(rootContext); } public Object computeValue(EvalContext context) { // Create a chain of contexts EvalContext rootContext;

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> if (isAbsolute()) { rootContext = context.getRootContext().getAbsoluteRootContext(); } else { rootContext = new InitialContext(context); } return getSingleNodePointerForSteps(rootContext); } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>())) { return null; } String property = nodeNameTest.isWildcard() ? null : testName.getName(); return createNodeIterator(property, reverse, startWith); } return test instanceof NodeTypeTest && ((NodeTypeTest) test).getNodeType() == Compiler.NODE_TYPE_NODE ? createNodeIterator(null, reverse, startWith) : null; } public NodeIterator createNodeIterator( String property, boolean reverse, NodePointer startWith) { return new PropertyIterator(this, property, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new BeanAttributeIterator(this, name); } protected PropertyOwnerPointer(NodePointer parent, Locale locale) { super(parent, locale); } protected PropertyOwnerPointer(NodePointer parent) { super(parent); } public void setIndex(int index) { if (this.index != index) { super.setIndex(index); value = UNINITIALIZED; } } private static final Object UNINITIALIZED = new Object(); private Object value = UNINITIALIZED; public Object getImmediateNode() { if (value == UNINITIALIZED) { value = index == WHOLE_COLLECTION ? ValueUtils.getValue(getBaseValue()) : ValueUtils.getValue(getBaseValue(), index); } return value; } public abstract QName getName(); /** * Throws an exception if you try to change the root element, otherwise * forwards the call to the parent pointer. */ public void setValue(Object value) { this.value = value; if (parent.isContainer()) { parent.setValue(value); } else if (parent != null) { if (index == WHOLE_COLLECTION) { throw new UnsupportedOperationException( "Cannot setValue of an object that is not " + "some other object's property"); } throw new JXPathInvalidAccessException( "The specified collection element does not exist: " + this); } else { throw new UnsupportedOperationException( "Cannot replace the root object"); } } /** * If this is a root node pointer, throws an exception; otherwise * forwards the call to the parent node. */ public void remove() { this.value = null

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>; } LocationStep(steps); } {if (true) return compiler.locationPath(false, steps.toArray());} throw new Error("Missing return statement in function"); } /* [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath */ /* [11] AbbreviatedRelativeLocationPath ::= RelativeLocationPath '//' Step */ /*--------------------*/ /* 2.1 Location Steps */ /*--------------------*/ /* [4] Step ::= AxisSpecifier NodeTest Predicate* | AbbreviatedStep */ final public void LocationStep(ArrayList steps) throws ParseException { Object t; Object s; switch (jj_nt.kind) { case SLASH: jj_consume_token(SLASH); break; case SLASHSLASH: jj_consume_token(SLASHSLASH); // Abbreviated step: descendant-or-self::node() t = compiler.nodeTypeTest(Compiler.NODE_TYPE_NODE); steps.add(compiler.step(Compiler.AXIS_DESCENDANT_OR_SELF, t, null)); break; default: jj_la1[9] = jj_gen; jj_consume_token(-1); throw new ParseException(); } NodeTest(steps); } /* [7] NodeTest ::= WildcardName | NodeType '(' ')' | 'processing-instruction' '(' Literal ')' */ final public void NodeTest(ArrayList steps) throws ParseException { int axis; int type = -1; String instruction = null; Object name = null; Object s; Object p; ArrayList ps = new ArrayList(); switch (jj_nt.kind) { case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case AXIS_SELF: case AXIS_CHILD: case AXIS_PARENT: case AXIS_ANCESTOR: case AXIS_ATTRIBUTE: case AXIS_NAMESPACE: case AXIS_PRECEDING: case AXIS_FOLLOWING: case AXIS_DESCENDANT: case AXIS_ANCESTOR_OR_SELF: case AXIS

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: case 88: name = WildcardName(); break; default: jj_la1[10] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } break; case 82: jj_consume_token(82); axis = Compiler.AXIS_SELF; type = Compiler.NODE_TYPE_NODE; break; case 83: jj_consume_token(83); axis = Compiler.AXIS_PARENT; type = Compiler.NODE_TYPE_NODE; break; default: jj_la1[11] = jj_gen; jj_consume_token(-1); throw new ParseException(); } label_3: while (true) { switch (jj_nt.kind) { case 84: ; break; default: jj_la1[12] = jj_gen; break label_3; } p = Predicate(); ps.add(p); } if (name != null){ s = compiler.nodeNameTest(name); } else if (instruction != null){ s = compiler.processingInstructionTest(instruction); } else { s = compiler.nodeTypeTest(type); } steps.add(compiler.step(axis, s, ps.toArray())); } /* [5] AxisSpecifier ::= AxisName '::' | AbbreviatedAxisSpecifier */ final public int AxisSpecifier() throws ParseException { int axis; switch (jj_nt.kind) { case AXIS_SELF: case

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>; Object arg; jj_consume_token(80); switch (jj_nt.kind) { case SLASH: case SLASHSLASH: case MINUS: case VARIABLE: case Literal: case Number: case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case AXIS_SELF: case AXIS_CHILD: case AXIS_PARENT: case AXIS_ANCESTOR: case AXIS_ATTRIBUTE: case AXIS_NAMESPACE: case AXIS_PRECEDING: case AXIS_FOLLOWING: case AXIS_DESCENDANT: case AXIS_ANCESTOR_OR_SELF: case AXIS_FOLLOWING_SIBLING: case AXIS_PRECEDING_SIBLING: case AXIS_DESCENDANT_OR_SELF: case FUNCTION_LAST: case FUNCTION_POSITION: case FUNCTION_COUNT: case FUNCTION_ID: case FUNCTION_KEY: case FUNCTION_LOCAL_NAME: case FUNCTION_NAMESPACE_URI: case FUNCTION_NAME: case FUNCTION_STRING: case FUNCTION_CONCAT: case FUNCTION_STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: case 80: case 82: case 83: case 86: case 88: arg = Argument(); args = new ArrayList(); args.add(arg); label_4: while (true) { switch (jj_nt.kind) { case 87: ; break; default: jj_la1[18] = jj

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>_gen; break label_4; } jj_consume_token(87); arg = Argument(); args.add(arg); } break; default: jj_la1[19] = jj_gen; ; } jj_consume_token(81); {if (true) return args;} throw new Error("Missing return statement in function"); } /* [17] Argument ::= Expr */ final public Object Argument() throws ParseException { Object ex; ex = Expression(); {if (true) return ex;} throw new Error("Missing return statement in function"); } /*---------------*/ /* 3.3 Node-sets */ /*---------------*/ /* [18] UnionExpr ::= PathExpr | UnionExpr '|' PathExpr */ final public Object UnionExpr() throws ParseException { Object ex, r; ArrayList list = null; ex = PathExpr(); label_5: while (true) { switch (jj_nt.kind) { case UNION: ; break; default: jj_la1[20] = jj_gen; break label_5; } jj_consume_token(UNION); r = PathExpr(); if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } if (list != null){ ex = compiler.union(list.toArray()); } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [19] PathExpr ::= LocationPath | FilterExpr | FilterExpr '/' RelativeLocationPath | FilterExpr '//' RelativeLocationPath */ final public Object PathExpr() throws ParseException { Object ex = null; Object[] steps; if (jj_2_6(2147483647)) { ex = FilterExpr(); } else { switch (jj_nt.kind) { case SLASH: case SLASHSLASH: case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case AXIS_SELF: case AXIS_CHILD: case AXIS

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> jj_gen; break label_6; } p = Predicate(); path = true; ps.add(p); } label_7: while (true) { switch (jj_nt.kind) { case SLASH: case SLASHSLASH: ; break; default: jj_la1[23] = jj_gen; break label_7; } LocationStep(steps); path = true; } if (path){ {if (true) return compiler.expressionPath(ex, ps.toArray(), steps.toArray());} } else { {if (true) return ex;} } throw new Error("Missing return statement in function"); } /*--------------*/ /* 3.4 Booleans */ /*--------------*/ /* [21] OrExpr ::= AndExpr | OrExpr 'or' AndExpr */ final public Object OrExpr() throws ParseException { Object ex, r; ArrayList list = null; ex = AndExpr(); label_8: while (true) { switch (jj_nt.kind) { case OR: ; break; default: jj_la1[24] = jj_gen; break label_8; } jj_consume_token(OR); r = AndExpr(); if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } if (list != null){ ex = compiler.or(list.toArray()); } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [22] AndExpr ::= EqualityExpr | AndExpr 'and' EqualityExpr */ final public Object AndExpr() throws ParseException { Object ex, r; ArrayList list = null; ex = EqualityExpr(); label_9: while (true) { switch (jj_nt.kind) { case AND: ; break; default: jj_la1[25] = jj_gen; break label_9; } jj_consume_token(AND); r = EqualityExpr(); if (list == null){ list

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> = new ArrayList(); list.add(ex); } list.add(r); } if (list != null){ ex = compiler.and(list.toArray()); } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [23] EqualityExpr ::= RelationalExpr | EqualityExpr '=' RelationalExpr | EqualityExpr '!=' RelationalExpr */ final public Object EqualityExpr() throws ParseException { Object ex, r; ex = RelationalExpr(); label_10: while (true) { switch (jj_nt.kind) { case EQ: case NEQ: ; break; default: jj_la1[26] = jj_gen; break label_10; } switch (jj_nt.kind) { case EQ: jj_consume_token(EQ); r = RelationalExpr(); ex = compiler.equal(ex, r); break; case NEQ: jj_consume_token(NEQ); r = RelationalExpr(); ex = compiler.notEqual(ex, r); break; default: jj_la1[27] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [24] RelationalExpr ::= AdditiveExpr | RelationalExpr '<' AdditiveExpr | RelationalExpr '>' AdditiveExpr | RelationalExpr '<=' AdditiveExpr | RelationalExpr '>=' AdditiveExpr */ final public Object RelationalExpr() throws ParseException { Object ex, r; ex = AdditiveExpr(); label_11: while (true) { switch (jj_nt.kind) { case LT: case LTE: case GT: case GTE: ; break; default: jj_la1[28] = jj_gen; break label_11; } switch (jj_nt.kind) { case LT: jj_consume_token(LT); r = AdditiveExpr(); ex = compiler.lessThan

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>(ex, r); break; case GT: jj_consume_token(GT); r = AdditiveExpr(); ex = compiler.greaterThan(ex, r); break; case LTE: jj_consume_token(LTE); r = AdditiveExpr(); ex = compiler.lessThanOrEqual(ex, r); break; case GTE: jj_consume_token(GTE); r = AdditiveExpr(); ex = compiler.greaterThanOrEqual(ex, r); break; default: jj_la1[29] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } {if (true) return ex;} throw new Error("Missing return statement in function"); } /*-------------*/ /* 3.5 Numbers */ /*-------------*/ /* [25] AdditiveExpr ::= MultiplicativeExpr | AdditiveExpr '+' MultiplicativeExpr | AdditiveExpr '-' MultiplicativeExpr */ final public Object AdditiveExpr() throws ParseException { Object ex, r; ArrayList list = null; ex = SubtractiveExpr(); label_12: while (true) { switch (jj_nt.kind) { case PLUS: ; break; default: jj_la1[30] = jj_gen; break label_12; } jj_consume_token(PLUS); r = SubtractiveExpr(); if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } if (list != null){ ex = compiler.sum(list.toArray()); } {if (true) return ex;} throw new Error("Missing return statement in function"); } final public Object SubtractiveExpr() throws ParseException { Object ex, r = null; ex = MultiplicativeExpr(); label_13: while (true) { switch (jj_nt.kind) { case MINUS: ; break; default: jj_la1[31] = jj_gen; break label_13; } jj_consume_token(MINUS); r = MultiplicativeExpr(); ex =

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xffffffff,0xffff0007,0xffff0007,0x0,0x7,}; } private static void jj_la1_2() { jj_la1_2 = new int[] {0x7fff,0x4000,0x3fff,0x8000,0x4000,0x14c7fff,0x0,0x0,0x0,0x0,0x1007fff,0x14c7fff,0x100000,0x0,0x0,0x400000,0x10000,0x7fff,0x800000,0x14d7fff,0x0,0x14c7fff,0x100000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1000000,0x1000000,0x14d7fff,0x1007fff,0x1007fff,0x8000,0x0,}; } final private JJCalls[] jj_2_rtns = new JJCalls[6]; private boolean jj_rescan = false; private int jj_gc = 0; public XPathParser(java.io.InputStream stream) { jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new XPathParserTokenManager(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> } public void ReInit(java.io.InputStream stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public XPathParser(java.io.Reader stream) { jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new XPathParserTokenManager(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public void ReInit(java.io.Reader stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public XPathParser(XPathParserTokenManager tm) { token_source = tm; token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public void ReInit(XPathParserTokenManager tm) { token_source = tm; token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } final private Token jj_consume_token(int kind) throws ParseException { Token oldToken = token; if ((token = jj_nt).next != null) jj_nt = jj_nt.next; else jj_nt = jj_nt.next = token_source.getNextToken(); if (token.kind == kind) { jj_gen++; if (++jj_gc > 100) { jj_gc = 0; for (int i = 0; i < jj_2_rtns.length; i++) { JJCalls c = jj_2_rtns[i]; while (c != null) { if (c.gen < jj_gen) c.first = null; c = c.next; } } } return token; } jj_nt = token; token = oldToken; jj_kind = kind; throw generateParseException(); } final private boolean jj_scan_token(int kind) { if (jj_scanpos == jj_lastpos) { jj_la--; if (jj_scanpos.next == null) { jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); } else { jj_lastpos = jj_scanpos = jj_scanpos.next; } } else { jj_scanpos = jj_scanpos.next; } if (jj_rescan) { int i = 0; Token tok = token; while (tok != null &&

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> tok != jj_scanpos) { i++; tok = tok.next; } if (tok != null) jj_add_error_token(kind, i); } return (jj_scanpos.kind != kind); } final public Token getNextToken() { if ((token = jj_nt).next != null) jj_nt = jj_nt.next; else jj_nt = jj_nt.next = token_source.getNextToken(); jj_gen++; return token; } final public Token getToken(int index) { Token t = lookingAhead ? jj_scanpos : token; for (int i = 0; i < index; i++) { if (t.next != null) t = t.next; else t = t.next = token_source.getNextToken(); } return t; } private java.util.Vector jj_expentries = new java.util.Vector(); private int[] jj_expentry; private int jj_kind = -1; private int[] jj_lasttokens = new int[100]; private int jj_endpos; private void jj_add_error_token(int kind, int pos) { if (pos >= 100) return; if (pos == jj_endpos + 1) { jj_lasttokens[jj_endpos++] = kind; } else if (jj_endpos != 0) { jj_expentry = new int[jj_endpos]; for (int i = 0; i < jj_endpos; i++) { jj_expentry[i] = jj_lasttokens[i]; } boolean exists = false; for (java.util.Enumeration en = jj_expentries.elements(); en.hasMoreElements();) { int[] oldentry = (int[])(en.nextElement()); if (oldentry.length == jj_expentry.length) { exists = true; for (int i = 0; i < jj_expentry.length; i++) { if (oldentry[i] != jj_expentry[i]) { exists = false; break; } } if (exists) break; } } if (!exists) jj

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>_token() { jj_rescan = true; for (int i = 0; i < 6; i++) { JJCalls p = jj_2_rtns[i]; do { if (p.gen > jj_gen) { jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; switch (i) { case 0: jj_3_1(); break; case 1: jj_3_2(); break; case 2: jj_3_3(); break; case 3: jj_3_4(); break; case 4: jj_3_5(); break; case 5: jj_3_6(); break; } } p = p.next; } while (p != null); } jj_rescan = false; } final private void jj_save(int index, int xla) { JJCalls p = jj_2_rtns[index]; while (p.gen > jj_gen) { if (p.next == null) { p = p.next = new JJCalls(); break; } p = p.next; } p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; } static final class JJCalls { int gen; Token first; int arg; JJCalls next; } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ package org.apache.commons.jxpath.ri.parser; /** * Describes the input token stream. */ public class Token { /** * An integer that describes the kind of this token. This numbering * system is determined by JavaCCParser, and a table of these numbers is * stored in the file ...Constants.java. */ public int kind; /** * beginLine and beginColumn describe the position of the first character * of this token; endLine and endColumn describe the position of the * last character of this token. */ public int beginLine, beginColumn, endLine, endColumn; /** * The string image of the token. */ public String image; /** * A reference to the next regular (non-special) token from the input * stream. If this is the last token from the input stream, or if the * token manager has not read tokens beyond this one, this field is * set to null. This is true only if this token is also a regular * token. Otherwise, see below for a description of the contents of * this field. */ public Token next; /** * This field is used to access special tokens that occur prior to this * token, but after the immediately preceding regular (non-special) token. * If there are no such special tokens, this field is set to null. * When there are more than one such special token, this field refers * to the last of these special tokens, which in turn refers to the next * previous special token through its specialToken field, and so on * until the first special token (whose specialToken field is null). * The next fields of special tokens refer to other special tokens that * immediately follow it (without an intervening regular token). If there * is no such token, this field is null. */ public Token specialToken; /** * Returns the image. */ public String toString() { return image; } /** * Returns a new Token object, by default. However, if you want, you * can create and return subclass objects based on the value of ofKind. * Simply add

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.Set; import org.apache.commons.jxpath.functions.ConstructorFunction; import org.apache.commons.jxpath.functions.MethodFunction; import org.apache.commons.jxpath.util.MethodLookupUtils; import org.apache.commons.jxpath.util.TypeUtils; /** * Extension functions provided by Java classes. The class prefix specified * in the constructor is used when a constructor or a static method is called. * Usually, a class prefix is a package name (hence the name of this class). * * Let's say, we declared a PackageFunction like this: * <blockquote><pre> * new PackageFunctions("java.util.", "util") * </pre></blockquote> * * We can now use XPaths like: * <dl> * <dt><code>"util:Date.new()"</code></dt> * <dd>Equivalent to <code>new java.util.Date()</code></dd> * <dt><code>"util:Collections.singleton('foo')"</code></dt> * <dd>Equivalent to <code>java.util.Collections.singleton("foo")</code></dd>

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>package.Classname.new</b>, if looking for a * constructor in a subpackage</li> * <li><b>Classname.methodname</b>, if looking for a static method</li> * <li><b>subpackage.subpackage.Classname.methodname</b>, if looking for a * static method of a class in a subpackage</li> * </ul> * * @return a MethodFunction, a ConstructorFunction or null if no function * is found */ public Function getFunction( String namespace, String name, Object[] parameters) { if ((namespace == null && this.namespace != null) || (namespace != null && !namespace.equals(this.namespace))) { return null; } if (parameters == null) { parameters = EMPTY_ARRAY; } if (parameters.length >= 1) { Object target = TypeUtils.convert(parameters[0], Object.class); if (target != null) { Method method = MethodLookupUtils.lookupMethod( target.getClass(), name, parameters); if (method != null) { return new MethodFunction(method); } if (target instanceof NodeSet) { target = ((NodeSet) target).getPointers(); } method = MethodLookupUtils.lookupMethod( target.getClass(), name, parameters); if (method != null) { return new MethodFunction(method); } if (target instanceof Collection) { Iterator iter = ((Collection) target).iterator(); if (iter.hasNext()) { target = iter.next(); if (target instanceof Pointer) { target = ((Pointer) target).getValue(); } } else { target = null; } } } if (target != null) { Method method = MethodLookupUtils.lookupMethod( target.getClass(), name, parameters); if (method != null) { return new MethodFunction(method); } } } String fullName = classPrefix + name; int inx = fullName.lastIndexOf('.'); if (inx == -1) { return null; } String className = fullName.substring(0, inx); String methodName = fullName.substring(inx +

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; import org.apache.commons.jxpath.ri.axes.InitialContext; import org.apache.commons.jxpath.ri.axes.SelfContext; /** * Common superclass for the implementations of Expression for the operations * "=" and "!=". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public abstract class CoreOperationCompare extends CoreOperation { public CoreOperationCompare(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } /** * Compares two values */ protected boolean equal( EvalContext context, Expression left, Expression right) { Object l = left.compute(context); Object r = right.compute(context); // System.err.println("COMPARING: " + // (l == null ? "null" : l.getClass().getName()) + " " + // (r == null ? "null" : r.getClass().getName())); if (l instanceof InitialContext) { ((EvalContext) l).reset

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>(); } if (l instanceof SelfContext) { l = ((EvalContext) l).getSingleNodePointer(); } if (r instanceof InitialContext) { ((EvalContext) r).reset(); } if (r instanceof SelfContext) { r = ((EvalContext) r).getSingleNodePointer(); } if (l instanceof Collection) { l = ((Collection) l).iterator(); } if (r instanceof Collection) { r = ((Collection) r).iterator(); } if ((l instanceof Iterator) && !(r instanceof Iterator)) { return contains((Iterator) l, r); } if (!(l instanceof Iterator) && (r instanceof Iterator)) { return contains((Iterator) r, l); } if (l instanceof Iterator && r instanceof Iterator) { return findMatch((Iterator) l, (Iterator) r); } return equal(l, r); } protected boolean contains(Iterator it, Object value) { while (it.hasNext()) { Object element = it.next(); if (equal(element, value)) { return true; } } return false; } protected boolean findMatch(Iterator lit, Iterator rit) { HashSet left = new HashSet(); while (lit.hasNext()) { left.add(lit.next()); } while (rit.hasNext()) { if (contains(left.iterator(), rit.next())) { return true; } } return false; } protected boolean equal(Object l, Object r) { if (l instanceof Pointer && r instanceof Pointer) { if (l.equals(r)) { return true; } } if (l instanceof Pointer) { l = ((Pointer) l).getValue(); } if (r instanceof Pointer) { r = ((Pointer) r).getValue(); } if (l == r) { return true; } // System.err.println("COMPARING VALUES: " + l + " " + r); if (l instanceof Boolean || r instanceof Boolean) { return (InfoSetUtil.booleanValue(l) == InfoSetUtil.booleanValue(r)); } if (l instanceof Number || r instanceof Number) { return (InfoSetUtil.doubleValue(l

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * Variables provide access to a global set of values accessible via XPath. * XPath can reference variables using the <code>"$varname"</code> syntax. * To use a custom implementation of this interface, pass it to * {@link JXPathContext#setVariables JXPathContext.setVariables()} * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public interface Variables { /** * Returns true if the specified variable is declared. */ boolean isDeclaredVariable(String varName); /** * Returns the value of the specified variable. * Throws IllegalArgumentException if there is no such variable. */ Object getVariable(String varName); /** * Defines a new variable with the specified value or modifies * the value of an existing variable. * May throw UnsupportedOperationException. */ void declareVariable(String varName, Object value); /** * Removes an existing variable. May throw UnsupportedOperationException. * * @param varName is a variable name without the "$" sign */ void undeclareVariable(String varName); }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.util.ValueUtils; import java.util.Collections; import java.util.Iterator; import java.util.Locale; /** * Common superclass for several types of nodes in the parse tree. Provides * APIs for optimization of evaluation of expressions. Specifically, an * expression only needs to executed once during the evaluation of an xpath * if that expression is context-independent. Expression.isContextDependent() * provides that hint. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public abstract class Expression { protected static final Double ZERO = new Double(0); protected static final Double ONE = new Double(1); protected static final Double NOT_A_NUMBER = new Double(Double.NaN); private boolean contextDependencyKnown = false; private boolean contextDependent; /** * Returns true if this expression should be re-evaluated * each time the current position in the context changes. */ public boolean isContextDependent() { if (!context

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>DependencyKnown) { contextDependent = computeContextDependent(); contextDependencyKnown = true; } return contextDependent; } /** * Implemented by subclasses and result is cached by isContextDependent() */ public abstract boolean computeContextDependent(); /** * Evaluates the expression. If the result is a node set, returns * the first element of the node set. */ public abstract Object computeValue(EvalContext context); public abstract Object compute(EvalContext context); public Iterator iterate(EvalContext context) { Object result = compute(context); if (result instanceof EvalContext) { return new ValueIterator((EvalContext) result); } if (result instanceof NodeSet) { return new ValueIterator(((NodeSet) result).getPointers().iterator()); } return ValueUtils.iterate(result); } public Iterator iteratePointers(EvalContext context) { Object result = compute(context); if (result == null) { return Collections.EMPTY_LIST.iterator(); } if (result instanceof EvalContext) { return (EvalContext) result; } if (result instanceof NodeSet) { return new PointerIterator(((NodeSet) result).getPointers().iterator(), new QName(null, "value"), context.getRootContext().getCurrentNodePointer().getLocale()); } return new PointerIterator(ValueUtils.iterate(result), new QName(null, "value"), context.getRootContext().getCurrentNodePointer().getLocale()); } public static class PointerIterator implements Iterator { private Iterator iterator; private QName qname; private Locale locale; //to what method does the following comment refer? /** * @deprecated Use the method that takes a NamespaceManager */ public PointerIterator(Iterator it, QName qname, Locale locale) { this.iterator = it; this.qname = qname; this.locale = locale; } public boolean hasNext() { return iterator.hasNext(); } public Object next() { Object o = iterator.next(); return o instanceof Pointer ? o : NodePointer.newNodePointer(qname, o, locale); } public void remove() { throw new UnsupportedOperationException(); } } public static class ValueIterator implements Iterator { private Iterator iterator; public ValueIterator(Iterator it) {

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> this.iterator = it; } public boolean hasNext() { return iterator.hasNext(); } public Object next() { Object o = iterator.next(); return o instanceof Pointer ? ((Pointer) o).getValue() : o; } public void remove() { throw new UnsupportedOperationException(); } } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * A Container is an object implementing an indirection * mechanism transparent to JXPath. For example, if property * "foo" of the context node has a Container as its value, * the XPath "foo" will produce the contents of that Container, * rather than the container itself. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public interface Container { /** * Returns the contained value. */ Object getValue(); /** * Modifies the value contained by this container. May throw * UnsupportedOperationException. */ void setValue(Object value); }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.QName; /** * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class TreeCompiler implements Compiler { private static final QName QNAME_NAME = new QName(null, "name"); public Object number(String value) { return new Constant(new Double(value)); } public Object literal(String value) { return new Constant(value); } public Object qname(String prefix, String name) { return new QName(prefix, name); } public Object sum(Object[] arguments) { return new CoreOperationAdd(toExpressionArray(arguments)); } public Object minus(Object left, Object right) { return new CoreOperationSubtract( (Expression) left, (Expression) right); } public Object multiply(Object left, Object right) { return new CoreOperationMultiply((Expression) left, (Expression) right); } public Object divide(Object left, Object right) { return new CoreOperationDivide((Expression) left, (Expression) right); } public Object mod(Object left, Object right) { return new CoreOperationMod((Expression) left, (Expression) right); } public Object lessThan(Object left, Object right) { return new CoreOperationLessThan((Expression)

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> left, (Expression) right); } public Object lessThanOrEqual(Object left, Object right) { return new CoreOperationLessThanOrEqual( (Expression) left, (Expression) right); } public Object greaterThan(Object left, Object right) { return new CoreOperationGreaterThan( (Expression) left, (Expression) right); } public Object greaterThanOrEqual(Object left, Object right) { return new CoreOperationGreaterThanOrEqual( (Expression) left, (Expression) right); } public Object equal(Object left, Object right) { return isNameAttributeTest((Expression) left) ? new NameAttributeTest((Expression) left, (Expression) right) : new CoreOperationEqual((Expression) left, (Expression) right); } public Object notEqual(Object left, Object right) { return new CoreOperationNotEqual((Expression) left, (Expression) right); } public Object minus(Object argument) { return new CoreOperationNegate((Expression) argument); } public Object variableReference(Object qName) { return new VariableReference((QName) qName); } public Object function(int code, Object[] args) { return new CoreFunction(code, toExpressionArray(args)); } public Object function(Object name, Object[] args) { return new ExtensionFunction((QName) name, toExpressionArray(args)); } public Object and(Object arguments[]) { return new CoreOperationAnd(toExpressionArray(arguments)); } public Object or(Object arguments[]) { return new CoreOperationOr(toExpressionArray(arguments)); } public Object union(Object[] arguments) { return new CoreOperationUnion(toExpressionArray(arguments)); } public Object locationPath(boolean absolute, Object[] steps) { return new LocationPath(absolute, toStepArray(steps)); } public Object expressionPath( Object expression, Object[] predicates, Object[] steps) { return new ExpressionPath( (Expression) expression, toExpressionArray(predicates), toStepArray(steps)); } public Object nodeNameTest(Object qname) { return new NodeNameTest((QName) qname); } public Object nodeTypeTest(int nodeType) { return new NodeTypeTest(nodeType);

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>RootContext() { return this; } public EvalContext getAbsoluteRootContext() { return jxpathContext.getAbsoluteRootContext(); } public NodePointer getCurrentNodePointer() { return pointer; } public Object getValue() { return pointer; } public int getCurrentPosition() { throw new UnsupportedOperationException(); } public boolean nextNode() { throw new UnsupportedOperationException(); } public boolean nextSet() { throw new UnsupportedOperationException(); } public boolean setPosition(int position) { throw new UnsupportedOperationException(); } public EvalContext getConstantContext(Object constant) { if (constant instanceof NodeSet) { return new NodeSetContext( new RootContext(jxpathContext, null), (NodeSet) constant); } NodePointer pointer; if (constant instanceof NodePointer) { pointer = (NodePointer) constant; } else { pointer = NodePointer.newNodePointer( new QName(null, ""), constant, null); } return new InitialContext(new RootContext(jxpathContext, pointer)); } public EvalContext getVariableContext(QName variableName) { return new InitialContext( new RootContext( jxpathContext, jxpathContext.getVariablePointer(variableName))); } public Function getFunction(QName functionName, Object[] parameters) { return jxpathContext.getFunction(functionName, parameters); } public Object getRegisteredValue(int id) { if (registers == null || id >= MAX_REGISTER || id == -1) { return UNKNOWN_VALUE; } return registers[id]; } public int setRegisteredValue(Object value) { if (registers == null) { registers = new Object[MAX_REGISTER]; for (int i = 0; i < MAX_REGISTER; i++) { registers[i] = UNKNOWN_VALUE; } } if (availableRegister >= MAX_REGISTER) { return -1; } registers[availableRegister] = value; availableRegister++; return availableRegister - 1; } public String toString() { return super.toString() + ":" + pointer.asPath(); } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>(Object object, String propertyName, Object value); }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> object has been created due to a parse error, the token * followng this token will (therefore) be the first error token. */ public Token currentToken; /** * Each entry in this array is an array of integers. Each array * of integers represents a sequence of tokens (by their ordinal * values) that is expected at this point of the parse. */ public int[][] expectedTokenSequences; /** * This is a reference to the "tokenImage" array of the generated * parser within which the parse error occurred. This array is * defined in the generated ...Constants interface. */ public String[] tokenImage; /** * This method has the standard behavior when this object has been * created using the standard constructors. Otherwise, it uses * "currentToken" and "expectedTokenSequences" to generate a parse * error message and returns it. If this object has been created * due to a parse error, and you do not catch it (it gets thrown * from the parser), then this method is called during the printing * of the final stack trace, and hence the correct error message * gets displayed. */ public String getMessage() { if (!specialConstructor) { return super.getMessage(); } String expected = ""; int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { if (maxSize < expectedTokenSequences[i].length) { maxSize = expectedTokenSequences[i].length; } for (int j = 0; j < expectedTokenSequences[i].length; j++) { expected += tokenImage[expectedTokenSequences[i][j]] + " "; } if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { expected += "..."; } expected += eol + " "; } String retval = "Encountered \""; Token tok = currentToken.next; for (int i = 0; i < maxSize; i++) { if (i != 0) retval += " "; if (tok.kind == 0) { retval += tokenImage[0]; break; } retval += add_escapes(tok.image); tok = tok.next;

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> } retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; retval += "." + eol; if (expectedTokenSequences.length == 1) { retval += "Was expecting:" + eol + " "; } else { retval += "Was expecting one of:" + eol + " "; } retval += expected; return retval; } /** * The end of line string for this machine. */ protected String eol = System.getProperty("line.separator", "\n"); /** * Used to convert raw characters to their escaped version * when these raw version cannot be used as part of an ASCII * string literal. */ protected String add_escapes(String str) { StringBuffer retval = new StringBuffer(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { case 0 : continue; case '\b': retval.append("\\b"); continue; case '\t': retval.append("\\t"); continue; case '\n': retval.append("\\n"); continue; case '\f': retval.append("\\f"); continue; case '\r': retval.append("\\r"); continue; case '\"': retval.append("\\\""); continue; case '\'': retval.append("\\\'"); continue; case '\\': retval.append("\\\\"); continue; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + s.substring(s.length() - 4, s.length())); } else { retval.append(ch); } continue; } } return retval.toString(); } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.VariablePointer; /** * Type conversions, XPath style. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class InfoSetUtil { private static final Double ZERO = new Double(0); private static final Double ONE = new Double(1); private static final Double NOT_A_NUMBER = new Double(Double.NaN); /** * Converts the supplied object to String */ public static String stringValue(Object object) { if (object instanceof String) { return (String) object; } if (object instanceof Number) { double d = ((Number) object).doubleValue(); long l = ((Number) object).longValue(); return d == l ? String.valueOf(l) : String.valueOf(d); } if (object instanceof Boolean) { return ((Boolean) object).booleanValue() ? "true" : "false"; } if (object == null) { return ""; } if (object instanceof NodePointer) { return stringValue(((NodePointer) object).getValue()); } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingle

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>NodePointer(); return ptr == null ? "" : stringValue(ptr); } return String.valueOf(object); } /** * Converts the supplied object to Number */ public static Number number(Object object) { if (object instanceof Number) { return (Number) object; } if (object instanceof Boolean) { return ((Boolean) object).booleanValue() ? ONE : ZERO; } if (object instanceof String) { try { return new Double((String) object); } catch (NumberFormatException ex) { return NOT_A_NUMBER; } } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingleNodePointer(); return ptr == null ? NOT_A_NUMBER : number(ptr); } if (object instanceof NodePointer) { return number(((NodePointer) object).getValue()); } return number(stringValue(object)); } /** * Converts the supplied object to double */ public static double doubleValue(Object object) { if (object instanceof Number) { return ((Number) object).doubleValue(); } if (object instanceof Boolean) { return ((Boolean) object).booleanValue() ? 0.0 : 1.0; } if (object instanceof String) { if (object.equals("")) { return 0.0; } try { return Double.parseDouble((String) object); } catch (NumberFormatException ex) { return Double.NaN; } } if (object instanceof NodePointer) { return doubleValue(((NodePointer) object).getValue()); } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingleNodePointer(); return ptr == null ? Double.NaN : doubleValue(ptr); } return doubleValue(stringValue(object)); } /** * Converts the supplied object to boolean */ public static boolean booleanValue(Object object) { if (object instanceof Number) { double value = ((Number) object).doubleValue(); return value != 0 && value != -0 && !Double.isNaN(value); } if (object instanceof Boolean) { return ((Boolean) object).booleanValue();

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingleNodePointer(); return ptr == null ? false : booleanValue(ptr); } if (object instanceof String) { return ((String) object).length() != 0; } if (object instanceof NodePointer) { NodePointer pointer = (NodePointer) object; if (pointer instanceof VariablePointer) { return booleanValue(pointer.getNode()); } pointer = pointer.getValuePointer(); return pointer.isActual(); } return object != null; } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; import java.lang.reflect.Array; import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.SortedSet; import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.Converter; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.JXPathTypeConversionException; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; /** * The default implementation of TypeConverter. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class BasicTypeConverter implements TypeConverter { /** * Returns true if it can convert the supplied * object to the specified class. */ public boolean canConvert(Object object, final Class toType) { if (object == null) { return true; } final Class useType = TypeUtils.wrapPrimitive(toType); Class fromType = object.getClass(); if (useType.isAssignableFrom

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>(fromType)) { return true; } if (useType == String.class) { return true; } if (object instanceof Boolean) { if (Number.class.isAssignableFrom(useType) || "java.util.concurrent.atomic.AtomicBoolean" .equals(useType.getName())) { return true; } } if (object instanceof Number) { if (Number.class.isAssignableFrom(useType) || useType == Boolean.class) { return true; } } if (object instanceof String) { if (useType == Boolean.class || useType == Character.class || useType == Byte.class || useType == Short.class || useType == Integer.class || useType == Long.class || useType == Float.class || useType == Double.class) { return true; } } if (fromType.isArray()) { // Collection -> array if (useType.isArray()) { Class cType = useType.getComponentType(); int length = Array.getLength(object); for (int i = 0; i < length; i++) { Object value = Array.get(object, i); if (!canConvert(value, cType)) { return false; } } return true; } if (Collection.class.isAssignableFrom(useType)) { return canCreateCollection(useType); } if (Array.getLength(object) > 0) { Object value = Array.get(object, 0); return canConvert(value, useType); } return canConvert("", useType); } if (object instanceof Collection) { // Collection -> array if (useType.isArray()) { Class cType = useType.getComponentType(); Iterator it = ((Collection) object).iterator(); while (it.hasNext()) { Object value = it.next(); if (!canConvert(value, cType)) { return false; } } return true; } if (Collection.class.isAssignableFrom(useType)) { return canCreateCollection(useType); } if (((Collection) object).size() > 0) { Object value; if (object instanceof List) { value

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> = ((List) object).get(0); } else { Iterator it = ((Collection) object).iterator(); value = it.next(); } return canConvert(value, useType); } return canConvert("", useType); } if (object instanceof NodeSet) { return canConvert(((NodeSet) object).getValues(), useType); } if (object instanceof Pointer) { return canConvert(((Pointer) object).getValue(), useType); } return ConvertUtils.lookup(useType) != null; } /** * Converts the supplied object to the specified * type. Throws a runtime exception if the conversion is * not possible. */ public Object convert(Object object, final Class toType) { if (object == null) { return toType.isPrimitive() ? convertNullToPrimitive(toType) : null; } if (toType == Object.class) { if (object instanceof NodeSet) { return convert(((NodeSet) object).getValues(), toType); } if (object instanceof Pointer) { return convert(((Pointer) object).getValue(), toType); } return object; } final Class useType = TypeUtils.wrapPrimitive(toType); Class fromType = object.getClass(); if (useType.isAssignableFrom(fromType)) { return object; } if (fromType.isArray()) { int length = Array.getLength(object); if (useType.isArray()) { Class cType = useType.getComponentType(); Object array = Array.newInstance(cType, length); for (int i = 0; i < length; i++) { Object value = Array.get(object, i); Array.set(array, i, convert(value, cType)); } return array; } if (Collection.class.isAssignableFrom(useType)) { Collection collection = allocateCollection(useType); for (int i = 0; i < length; i++) { collection.add(Array.get(object, i)); } return unmodifiableCollection(collection); } if (length > 0) { Object value = Array.get(object, 0); return convert(value, useType); } return convert("", use

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>Type); } if (object instanceof Collection) { int length = ((Collection) object).size(); if (useType.isArray()) { Class cType = useType.getComponentType(); Object array = Array.newInstance(cType, length); Iterator it = ((Collection) object).iterator(); for (int i = 0; i < length; i++) { Object value = it.next(); Array.set(array, i, convert(value, cType)); } return array; } if (Collection.class.isAssignableFrom(useType)) { Collection collection = allocateCollection(useType); collection.addAll((Collection) object); return unmodifiableCollection(collection); } if (length > 0) { Object value; if (object instanceof List) { value = ((List) object).get(0); } else { Iterator it = ((Collection) object).iterator(); value = it.next(); } return convert(value, useType); } return convert("", useType); } if (object instanceof NodeSet) { return convert(((NodeSet) object).getValues(), useType); } if (object instanceof Pointer) { return convert(((Pointer) object).getValue(), useType); } if (useType == String.class) { return object.toString(); } if (object instanceof Boolean) { if (Number.class.isAssignableFrom(useType)) { return allocateNumber(useType, ((Boolean) object).booleanValue() ? 1 : 0); } if ("java.util.concurrent.atomic.AtomicBoolean".equals(useType.getName())) { try { return useType.getConstructor(new Class[] { boolean.class }) .newInstance(new Object[] { object }); } catch (Exception e) { throw new JXPathTypeConversionException(useType.getName(), e); } } } if (object instanceof Number) { double value = ((Number) object).doubleValue(); if (useType == Boolean.class) { return value == 0.0 ? Boolean.FALSE : Boolean.TRUE; } if (Number.class.isAssignableFrom(useType)) { return allocateNumber(useType, value); } } if (object

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> instanceof String) { Object value = convertStringToPrimitive(object, useType); if (value != null) { return value; } } Converter converter = ConvertUtils.lookup(useType); if (converter != null) { return converter.convert(useType, object); } throw new JXPathTypeConversionException("Cannot convert " + object.getClass() + " to " + useType); } protected Object convertNullToPrimitive(Class toType) { if (toType == boolean.class) { return Boolean.FALSE; } if (toType == char.class) { return new Character('\0'); } if (toType == byte.class) { return new Byte((byte) 0); } if (toType == short.class) { return new Short((short) 0); } if (toType == int.class) { return new Integer(0); } if (toType == long.class) { return new Long(0L); } if (toType == float.class) { return new Float(0.0f); } if (toType == double.class) { return new Double(0.0); } return null; } protected Object convertStringToPrimitive(Object object, Class toType) { toType = TypeUtils.wrapPrimitive(toType); if (toType == Boolean.class) { return Boolean.valueOf((String) object); } if (toType == Character.class) { return new Character(((String) object).charAt(0)); } if (toType == Byte.class) { return new Byte((String) object); } if (toType == Short.class) { return new Short((String) object); } if (toType == Integer.class) { return new Integer((String) object); } if (toType == Long.class) { return new Long((String) object); } if (toType == Float.class) { return new Float((String) object); } if (toType == Double.class) { return new Double((String) object); } return null; } protected Number allocateNumber(Class type, double

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> value) { type = TypeUtils.wrapPrimitive(type); if (type == Byte.class) { return new Byte((byte) value); } if (type == Short.class) { return new Short((short) value); } if (type == Integer.class) { return new Integer((int) value); } if (type == Long.class) { return new Long((long) value); } if (type == Float.class) { return new Float((float) value); } if (type == Double.class) { return new Double(value); } if (type == BigInteger.class) { return BigInteger.valueOf((long) value); } if (type == BigDecimal.class) { return new BigDecimal(value); } String classname = type.getName(); Class initialValueType = null; if ("java.util.concurrent.atomic.AtomicInteger".equals(classname)) { initialValueType = int.class; } if ("java.util.concurrent.atomic.AtomicLong".equals(classname)) { initialValueType = long.class; } if (initialValueType != null) { try { return (Number) type.getConstructor( new Class[] { initialValueType }) .newInstance( new Object[] { allocateNumber(initialValueType, value) }); } catch (Exception e) { throw new JXPathTypeConversionException(classname, e); } } return null; } protected boolean canCreateCollection(Class type) { if (!type.isInterface() && ((type.getModifiers() & Modifier.ABSTRACT) == 0)) { try { type.getConstructor(new Class[0]); return true; } catch (Exception e) { return false; } } return type == List.class || type == Collection.class || type == Set.class; } protected Collection allocateCollection(Class type) { if (!type.isInterface() && ((type.getModifiers() & Modifier.ABSTRACT) == 0)) { try { return (Collection) type.newInstance(); } catch (Exception ex) { throw new JXPathInvalidAccessException( "Cannot create collection of type: " + type, ex);

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> } } if (type == List.class || type == Collection.class) { return new ArrayList(); } if (type == Set.class) { return new HashSet(); } throw new JXPathInvalidAccessException( "Cannot create collection of type: " + type); } protected Collection unmodifiableCollection(Collection collection) { if (collection instanceof List) { return Collections.unmodifiableList((List) collection); } if (collection instanceof SortedSet) { return Collections.unmodifiableSortedSet((SortedSet) collection); } if (collection instanceof Set) { return Collections.unmodifiableSet((Set) collection); } return Collections.unmodifiableCollection(collection); } static final class ValueNodeSet implements NodeSet { private List values; private List pointers; public ValueNodeSet(List values) { this.values = values; } public List getValues() { return Collections.unmodifiableList(values); } public List getNodes() { return Collections.unmodifiableList(values); } public List getPointers() { if (pointers == null) { pointers = new ArrayList(); for (int i = 0; i < values.size(); i++) { pointers.add(new ValuePointer(values.get(i))); } pointers = Collections.unmodifiableList(pointers); } return pointers; } } static final class ValuePointer implements Pointer { private Object bean; public ValuePointer(Object object) { this.bean = object; } public Object getValue() { return bean; } public Object getNode() { return bean; } public Object getRootNode() { return bean; } public void setValue(Object value) { throw new UnsupportedOperationException(); } public Object clone() { return this; } public int compareTo(Object object) { return 0; } public String asPath() { if (bean == null) { return "null()"; } if (bean instanceof Number) { String string = bean.toString(); if (string.endsWith(".0")) { string = string.substring(0, string.length() - 2); } return string; } if (bean instanceof Boolean) { return ((Boolean) bean).

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * A single-set EvalContext that provides access to the current node of * the parent context and nothing else. It does not pass the iteration * on to the parent context. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class InitialContext extends EvalContext { private boolean started = false; private boolean collection; private NodePointer nodePointer; public InitialContext(EvalContext parentContext) { super(parentContext); nodePointer = (NodePointer) parentContext.getCurrentNodePointer().clone(); if (nodePointer != null) { collection = (nodePointer.getIndex() == NodePointer.WHOLE_COLLECTION); } } public Pointer getSingleNodePointer() { return nodePointer; } public NodePointer getCurrentNodePointer() { return nodePointer; } public Object getValue() { return nodePointer.getValue(); } public boolean nextNode() { return setPosition(position + 1); } public boolean setPosition(int position) { this.position = position; if (collection) { if (position >= 1 && position <= nodePointer.getLength())

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.Iterator; /** * Represents a compiled XPath. The interpretation of compiled XPaths * may be faster, because it bypasses the compilation step. The reference * implementation of JXPathContext also globally caches some of the * results of compilation, so the direct use of JXPathContext is not * always less efficient than the use of CompiledExpression. * <p> * Use CompiledExpression only when there is a need to evaluate the * same expression multiple times and the CompiledExpression can be * conveniently cached. * <p> * To acqure a CompiledExpression, call {@link JXPathContext#compile * JXPathContext.compile} * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public interface CompiledExpression { /** * Evaluates the xpath and returns the resulting object. Primitive * types are wrapped into objects. */ Object getValue(JXPathContext context); /** * Evaluates the xpath, converts the result to the specified class and * returns the resulting object. */ Object getValue(JXPathContext context, Class requiredType); /** * Modifies the value of the property described by the supplied xpath. * Will throw an exception if one of the following conditions occurs: * <ul> * <li>The xpath does not in fact describe an existing property * <li>The property is not writable

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> (no public, non-static set method) * </ul> */ void setValue(JXPathContext context, Object value); /** * Creates intermediate elements of * the path by invoking an AbstractFactory, which should first be * installed on the context by calling "setFactory". */ Pointer createPath(JXPathContext context); /** * The same as setValue, except it creates intermediate elements of * the path by invoking an AbstractFactory, which should first be * installed on the context by calling "setFactory". * <p> * Will throw an exception if one of the following conditions occurs: * <ul> * <li>Elements of the xpath aleady exist, by the path does not in * fact describe an existing property * <li>The AbstractFactory fails to create an instance for an intermediate * element. * <li>The property is not writable (no public, non-static set method) * </ul> */ Pointer createPathAndSetValue(JXPathContext context, Object value); /** * Traverses the xpath and returns a Iterator of all results found * for the path. If the xpath matches no properties * in the graph, the Iterator will not be null. */ Iterator iterate(JXPathContext context); /** * Traverses the xpath and returns a Pointer. * A Pointer provides easy access to a property. * If the xpath matches no properties * in the graph, the pointer will be null. */ Pointer getPointer(JXPathContext context, String xpath); /** * Traverses the xpath and returns an Iterator of Pointers. * A Pointer provides easy access to a property. * If the xpath matches no properties * in the graph, the Iterator be empty, but not null. */ Iterator iteratePointers(JXPathContext context); /** * Remove the graph element described by this expression */ void removePath(JXPathContext context); /** * Remove all graph elements described by this expression */ void removeAll(JXPathContext context); }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> = index; setIndex(WHOLE_COLLECTION); } } public Object getBean() { if (bean == null) { bean = getImmediateParentPointer().getNode(); } return bean; } public QName getName() { return new QName(null, getPropertyName()); } public abstract String getPropertyName(); public abstract void setPropertyName(String propertyName); public abstract int getPropertyCount(); public abstract String[] getPropertyNames(); protected abstract boolean isActualProperty(); public boolean isActual() { if (!isActualProperty()) { return false; } return super.isActual(); } private static final Object UNINITIALIZED = new Object(); private Object value = UNINITIALIZED; public Object getImmediateNode() { if (value == UNINITIALIZED) { value = index == WHOLE_COLLECTION ? ValueUtils.getValue(getBaseValue()) : ValueUtils.getValue(getBaseValue(), index); } return value; } public boolean isCollection() { Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } /** * If the property contains a collection, then the length of that * collection, otherwise - 1. */ public int getLength() { return ValueUtils.getLength(getBaseValue()); } /** * Returns a NodePointer that can be used to access the currently * selected property value. */ public NodePointer getImmediateValuePointer() { return NodePointer.newChildNodePointer( (NodePointer) this.clone(), getName(), getImmediateNode()); } public NodePointer createPath(JXPathContext context) { if (getImmediateNode() == null) { AbstractFactory factory = getAbstractFactory(context); int inx = (index == WHOLE_COLLECTION ? 0 : index); boolean success = factory.createObject( context, this, getBean(), getPropertyName(), inx); if (!success) { throw new JXPathAbstractFactoryException("Factory " + factory + " could not create an object for path: " + asPath());

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> } } return this; } public NodePointer createPath(JXPathContext context, Object value) { // If neccessary, expand collection if (index != WHOLE_COLLECTION && index >= getLength()) { createPath(context); } setValue(value); return this; } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { PropertyPointer prop = (PropertyPointer) clone(); if (name != null) { prop.setPropertyName(name.toString()); } prop.setIndex(index); return prop.createPath(context, value); } public NodePointer createChild( JXPathContext context, QName name, int index) { PropertyPointer prop = (PropertyPointer) clone(); if (name != null) { prop.setPropertyName(name.toString()); } prop.setIndex(index); return prop.createPath(context); } public int hashCode() { return getImmediateParentPointer().hashCode() + propertyIndex + index; } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof PropertyPointer)) { return false; } PropertyPointer other = (PropertyPointer) object; if (parent != other.parent && (parent == null || !parent.equals(other.parent))) { return false; } if (getPropertyIndex() != other.getPropertyIndex() || !getPropertyName().equals(other.getPropertyName())) { return false; } int iThis = (index == WHOLE_COLLECTION ? 0 : index); int iOther = (other.index == WHOLE_COLLECTION ? 0 : other.index); return iThis == iOther; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { return getValuePointer().compareChildNodePointers(pointer1, pointer2); } private AbstractFactory getAbstractFactory(JXPathContext context) { AbstractFactory factory = context.getFactory(); if (factory == null) { throw new JXPathException( "Factory is not set on the " + "JXPathContext - cannot create path: "

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>Info; } public PropertyPointer getPropertyPointer() { return new BeanPropertyPointer(this, beanInfo); } public QName getName() { return name; } /** * Returns the bean itself */ public Object getBaseValue() { return bean; } /** * Returns false */ public boolean isCollection() { return false; } /** * Returns 1. */ public int getLength() { return 1; } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public int hashCode() { return name == null ? 0 : name.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof BeanPointer)) { return false; } BeanPointer other = (BeanPointer) object; if (parent != other.parent) { if (parent == null || !parent.equals(other.parent)) { return false; } } if ((name == null && other.name != null) || (name != null && !name.equals(other.name))) { return false; } int iThis = (index == WHOLE_COLLECTION ? 0 : index); int iOther = (other.index == WHOLE_COLLECTION ? 0 : other.index); if (iThis != iOther) { return false; } if (bean instanceof Number || bean instanceof String || bean instanceof Boolean) { return bean.equals(other.bean); } return bean == other.bean; } /** * If the pointer has a parent, then parent's path. * If the bean is null, "null()". * If the bean is a primitive value, the value itself. * Otherwise - an empty string. */ public String asPath() { if (parent != null) { return super.asPath(); } if (bean == null) { return "null()"; } if (bean instanceof Number) { String string = bean.toString(); if (string.endsWith(".0")) { string = string.substring(

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; /** * The common subclass for tree elements representing core operations like "+", * "- ", "*" etc. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public abstract class CoreOperation extends Operation { public CoreOperation(Expression args[]) { super(args); } public Object compute(EvalContext context) { return computeValue(context); } public abstract Object computeValue(EvalContext context); /** * Returns the XPath symbol for this operation, e.g. "+", "div", etc. */ public abstract String getSymbol(); /** * Returns true if the operation is not sensitive to the order of arguments, * e.g. "=", "and" etc, and false if it is, e.g. "&lt;=", "div". */ protected abstract boolean isSymmetric(); /** * Computes the precedence of the operation. */ protected abstract int getPrecedence(); public String toString() { if (args.length == 1) { return getSymbol() + parenthesize(args[0], false); } StringBuffer buffer = new StringBuffer(); for (int i = 0; i < args.length; i++) { if (i > 0) { buffer.append(' '); buffer.append(getSymbol()); buffer.append(' ');

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> } buffer.append(parenthesize(args[i], i == 0)); } return buffer.toString(); } private String parenthesize(Expression expression, boolean left) { String s = expression.toString(); if (!(expression instanceof CoreOperation)) { return s; } int compared = getPrecedence() - ((CoreOperation) expression).getPrecedence(); if (compared < 0) { return s; } if (compared == 0 && (isSymmetric() || left)) { return s; } return '(' + s + ')'; } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> DynamicPropertyHandler handler) { super(parent); this.name = name; this.bean = bean; this.handler = handler; } public PropertyPointer getPropertyPointer() { return new DynamicPropertyPointer(this, handler); } public NodeIterator createNodeIterator( String property, boolean reverse, NodePointer startWith) { return new PropertyIterator(this, property, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new DynamicAttributeIterator(this, name); } public QName getName() { return name; } public boolean isDynamicPropertyDeclarationSupported() { return true; } /** * Returns the DP object iself. */ public Object getBaseValue() { return bean; } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public boolean isCollection() { return false; } /** * Returns 1. */ public int getLength() { return 1; } public String asPath() { return parent == null ? "/" : super.asPath(); } public int hashCode() { return System.identityHashCode(bean) + name.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof DynamicPointer)) { return false; } DynamicPointer other = (DynamicPointer) object; return bean == other.bean && name.equals(other.name); } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; import java.beans.IndexedPropertyDescriptor; import java.beans.PropertyDescriptor; import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.commons.jxpath.Container; import org.apache.commons.jxpath.DynamicPropertyHandler; import org.apache.commons.jxpath.JXPathException; /** * Collection and property access utilities. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class ValueUtils { private static Map dynamicPropertyHandlerMap = new HashMap(); private static final int UNKNOWN_LENGTH_MAX_COUNT = 16000; /** * Returns true if the object is an array or a Collection */ public static boolean isCollection(Object value) { if (value == null) { return false; } value = getValue(value); if (value.getClass().isArray()) { return true; } if (value instanceof Collection) { return true; } return false;

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> } /** * Returns 1 if the type is a collection, * -1 if it is definitely not * and 0 if it may be a collection in some cases. */ public static int getCollectionHint(Class clazz) { if (clazz.isArray()) { return 1; } if (Collection.class.isAssignableFrom(clazz)) { return 1; } if (clazz.isPrimitive()) { return -1; } if (clazz.isInterface()) { return 0; } if (Modifier.isFinal(clazz.getModifiers())) { return -1; } return 0; } /** * If there is a regular non-indexed read method for this property, * uses this method to obtain the collection and then returns its * length. * Otherwise, attempts to guess the length of the collection by * calling the indexed get method repeatedly. The method is supposed * to throw an exception if the index is out of bounds. */ public static int getIndexedPropertyLength( Object object, IndexedPropertyDescriptor pd) { if (pd.getReadMethod() != null) { return getLength(getValue(object, pd)); } Method readMethod = pd.getIndexedReadMethod(); if (readMethod == null) { throw new JXPathException( "No indexed read method for property " + pd.getName()); } for (int i = 0; i < UNKNOWN_LENGTH_MAX_COUNT; i++) { try { readMethod.invoke(object, new Object[] { new Integer(i)}); } catch (Throwable t) { return i; } } throw new JXPathException( "Cannot determine the length of the indexed property " + pd.getName()); } /** * Returns the length of the supplied collection. If the supplied object * is not a collection, returns 1. If collection is null, returns 0. */ public static int getLength(Object collection) { if (collection == null) { return 0; } collection = getValue(collection); if (collection.getClass().isArray()) { return Array.getLength(collection); } if (collection instanceof Collection) { return ((Collection) collection).size();

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> } return 1; } /** * Returns an iterator for the supplied collection. If the argument * is null, returns an empty iterator. If the argument is not * a collection, returns an iterator that produces just that one object. */ public static Iterator iterate(Object collection) { if (collection == null) { return Collections.EMPTY_LIST.iterator(); } if (collection.getClass().isArray()) { int length = Array.getLength(collection); if (length == 0) { return Collections.EMPTY_LIST.iterator(); } ArrayList list = new ArrayList(); for (int i = 0; i < length; i++) { list.add(Array.get(collection, i)); } return list.iterator(); } if (collection instanceof Collection) { return ((Collection) collection).iterator(); } return Collections.singletonList(collection).iterator(); } /** * Grows the collection if necessary to the specified size. Returns * the new, expanded collection. */ public static Object expandCollection(Object collection, int size) { if (collection == null) { return null; } if (collection.getClass().isArray()) { Object bigger = Array.newInstance( collection.getClass().getComponentType(), size); System.arraycopy( collection, 0, bigger, 0, Array.getLength(collection)); return bigger; } if (collection instanceof Collection) { while (((Collection) collection).size() < size) { ((Collection) collection).add(null); } return collection; } throw new JXPathException( "Cannot turn " + collection.getClass().getName() + " into a collection of size " + size); } /** * Returns the index'th element from the supplied collection. */ public static Object remove(Object collection, int index) { collection = getValue(collection); if (collection == null) { return null; } if (collection.getClass().isArray()) { int length = Array.getLength(collection); Object smaller = Array.newInstance( collection.getClass().getComponentType(), length - 1); if (index > 0) { System.arraycopy(collection, 0, smaller, 0

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>, index); } if (index < length - 1) { System.arraycopy( collection, index + 1, smaller, index, length - index - 1); } return smaller; } if (collection instanceof List) { int size = ((List) collection).size(); if (index < size) { ((List) collection).remove(index); } return collection; } if (collection instanceof Collection) { Iterator it = ((Collection) collection).iterator(); for (int i = 0; i < index; i++) { if (!it.hasNext()) { break; } it.next(); } if (it.hasNext()) { it.next(); it.remove(); } return collection; } throw new JXPathException( "Cannot remove " + collection.getClass().getName() + "[" + index + "]"); } /** * Returns the index'th element of the supplied collection. */ public static Object getValue(Object collection, int index) { collection = getValue(collection); Object value = collection; if (collection != null) { if (collection.getClass().isArray()) { if (index < 0 || index >= Array.getLength(collection)) { return null; } value = Array.get(collection, index); } else if (collection instanceof List) { if (index < 0 || index >= ((List) collection).size()) { return null; } value = ((List) collection).get(index); } else if (collection instanceof Collection) { int i = 0; Iterator it = ((Collection) collection).iterator(); for (; i < index; i++) { it.next(); } if (it.hasNext()) { value = it.next(); } else { value = null; } } } return value; } /** * Modifies the index'th element of the supplied collection. * Converts the value to the required type if necessary. */ public static void setValue(Object collection, int index, Object value) { collection = getValue(collection); if (collection != null) { if (collection.getClass().isArray()) { Array.

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>set( collection, index, convert(value, collection.getClass().getComponentType())); } else if (collection instanceof List) { ((List) collection).set(index, value); } else if (collection instanceof Collection) { throw new UnsupportedOperationException( "Cannot set value of an element of a " + collection.getClass().getName()); } } } /** * Returns the value of the bean's property represented by * the supplied property descriptor. */ public static Object getValue( Object bean, PropertyDescriptor propertyDescriptor) { Object value; try { Method method = getAccessibleMethod(propertyDescriptor.getReadMethod()); if (method == null) { throw new JXPathException("No read method"); } value = method.invoke(bean, new Object[0]); } catch (Exception ex) { throw new JXPathException( "Cannot access property: " + (bean == null ? "null" : bean.getClass().getName()) + "." + propertyDescriptor.getName(), ex); } return value; } /** * Modifies the value of the bean's property represented by * the supplied property descriptor. */ public static void setValue( Object bean, PropertyDescriptor propertyDescriptor, Object value) { try { Method method = getAccessibleMethod(propertyDescriptor.getWriteMethod()); if (method == null) { throw new JXPathException("No write method"); } value = convert(value, propertyDescriptor.getPropertyType()); value = method.invoke(bean, new Object[] { value }); } catch (Exception ex) { throw new JXPathException( "Cannot modify property: " + (bean == null ? "null" : bean.getClass().getName()) + "." + propertyDescriptor.getName(), ex); } } private static Object convert(Object value, Class type) { try { return TypeUtils.convert(value, type); } catch (Exception ex) { throw new JXPathException( "Cannot convert value of class " + (value == null ? "null" : value.getClass().getName()) + " to type " + type, ex); } } /** * Returns the index'th

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> element of the bean's property represented by * the supplied property descriptor. */ public static Object getValue( Object bean, PropertyDescriptor propertyDescriptor, int index) { if (propertyDescriptor instanceof IndexedPropertyDescriptor) { try { IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) propertyDescriptor; Method method = ipd.getIndexedReadMethod(); if (method != null) { return method.invoke( bean, new Object[] { new Integer(index)}); } } catch (InvocationTargetException ex) { Throwable t = ex.getTargetException(); if (t instanceof IndexOutOfBoundsException) { return null; } throw new JXPathException( "Cannot access property: " + propertyDescriptor.getName(), t); } catch (Throwable ex) { throw new JXPathException( "Cannot access property: " + propertyDescriptor.getName(), ex); } } // We will fall through if there is no indexed read return getValue(getValue(bean, propertyDescriptor), index); } /** * Modifies the index'th element of the bean's property represented by * the supplied property descriptor. Converts the value to the required * type if necessary. */ public static void setValue( Object bean, PropertyDescriptor propertyDescriptor, int index, Object value) { if (propertyDescriptor instanceof IndexedPropertyDescriptor) { try { IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) propertyDescriptor; Method method = ipd.getIndexedWriteMethod(); if (method != null) { method.invoke( bean, new Object[] { new Integer(index), convert(value, ipd.getIndexedPropertyType())}); return; } } catch (Exception ex) { throw new RuntimeException( "Cannot access property: " + propertyDescriptor.getName() + ", " + ex.getMessage()); } } // We will fall through if there is no indexed read Object collection = getValue(bean, propertyDescriptor); if (isCollection(collection)) { setValue(collection, index, value); } else if (index == 0) { setValue(bean, propertyDescriptor, value); } else { throw new RuntimeException( "Not a collection: " + propertyDescriptor.getName

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> return collection; } public boolean isCollection() { return true; } public int getLength() { return ValueUtils.getLength(getBaseValue()); } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public boolean isContainer() { return index != WHOLE_COLLECTION; } public Object getImmediateNode() { return index == WHOLE_COLLECTION ? ValueUtils.getValue(collection) : ValueUtils.getValue(collection, index); } public void setValue(Object value) { if (index == WHOLE_COLLECTION) { parent.setValue(value); } else { ValueUtils.setValue(collection, index, value); } } public void setIndex(int index) { super.setIndex(index); valuePointer = null; } public NodePointer getValuePointer() { if (valuePointer == null) { if (index == WHOLE_COLLECTION) { valuePointer = this; } else { Object value = getImmediateNode(); valuePointer = NodePointer.newChildNodePointer(this, getName(), value); } } return valuePointer; } public NodePointer createPath(JXPathContext context) { Object collection = getBaseValue(); if (ValueUtils.getLength(collection) <= index) { collection = ValueUtils.expandCollection(getNode(), index + 1); } return this; } public NodePointer createPath(JXPathContext context, Object value) { NodePointer ptr = createPath(context); ptr.setValue(value); return ptr; } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { NodePointer ptr = (NodePointer) clone(); ptr.setIndex(index); return ptr.createPath(context, value); } public NodePointer createChild( JXPathContext context, QName name, int index) { NodePointer ptr = (NodePointer) clone(); ptr.setIndex(index); return ptr.createPath(context); } public int hashCode() { return System.identityHashCode(collection

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Vector; import java.util.Map.Entry; import org.apache.commons.jxpath.CompiledExpression; import org.apache.commons.jxpath.Function; import org.apache.commons.jxpath.Functions; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.JXPathFunctionNotFoundException; import org.apache.commons.jxpath.JXPathInvalidSyntaxException; import org.apache.commons.jxpath.JXPathNotFoundException; import org.apache.commons.jxpath.JXPathTypeConversionException; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.Variables; import org.apache.commons.jxpath.ri.axes.InitialContext; import org.apache.commons.jxpath.ri.axes.RootContext; import org.apache.commons.jxpath.ri.compiler.Expression; import org.apache.commons.jxpath.ri.compiler.LocationPath;

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> import org.apache.commons.jxpath.ri.compiler.Path; import org.apache.commons.jxpath.ri.compiler.TreeCompiler; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; import org.apache.commons.jxpath.ri.model.VariablePointer; import org.apache.commons.jxpath.ri.model.beans.BeanPointerFactory; import org.apache.commons.jxpath.ri.model.beans.CollectionPointerFactory; import org.apache.commons.jxpath.ri.model.container.ContainerPointerFactory; import org.apache.commons.jxpath.ri.model.dynamic.DynamicPointerFactory; import org.apache.commons.jxpath.util.ReverseComparator; import org.apache.commons.jxpath.util.TypeUtils; /** * The reference implementation of JXPathContext. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class JXPathContextReferenceImpl extends JXPathContext { /** * Change this to <code>false</code> to disable soft caching of * CompiledExpressions. */ public static final boolean USE_SOFT_CACHE = true; private static final Compiler COMPILER = new TreeCompiler(); private static Map compiled = new HashMap(); private static int cleanupCount = 0; private static Vector nodeFactories = new Vector(); private static NodePointerFactory nodeFactoryArray[] = null; static { nodeFactories.add(new CollectionPointerFactory()); nodeFactories.add(new BeanPointerFactory()); nodeFactories.add(new DynamicPointerFactory()); // DOM factory is only registered if DOM support is on the classpath Object domFactory = allocateConditionally( "org.apache.commons.jxpath.ri.model.dom.DOMPointerFactory", "org.w3c.dom.Node"); if (domFactory != null) { nodeFactories.add(domFactory); } // JDOM factory is only registered if JDOM is on the classpath Object jdomFactory = allocateConditionally( "org.apache.commons.jxpath.ri.model.jdom

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>.JDOMPointerFactory", "org.jdom.Document"); if (jdomFactory != null) { nodeFactories.add(jdomFactory); } // DynaBean factory is only registered if BeanUtils are on the classpath Object dynaBeanFactory = allocateConditionally( "org.apache.commons.jxpath.ri.model.dynabeans." + "DynaBeanPointerFactory", "org.apache.commons.beanutils.DynaBean"); if (dynaBeanFactory != null) { nodeFactories.add(dynaBeanFactory); } nodeFactories.add(new ContainerPointerFactory()); createNodeFactoryArray(); } private Pointer rootPointer; private Pointer contextPointer; protected NamespaceResolver namespaceResolver; // The frequency of the cache cleanup private static final int CLEANUP_THRESHOLD = 500; protected JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean) { this(parentContext, contextBean, null); } public JXPathContextReferenceImpl( JXPathContext parentContext, Object contextBean, Pointer contextPointer) { super(parentContext, contextBean); synchronized (nodeFactories) { createNodeFactoryArray(); } if (contextPointer != null) { this.contextPointer = contextPointer; this.rootPointer = NodePointer.newNodePointer( new QName(null, "root"), contextPointer.getRootNode(), getLocale()); } else { this.contextPointer = NodePointer.newNodePointer( new QName(null, "root"), contextBean, getLocale()); this.rootPointer = this.contextPointer; } NamespaceResolver parentNR = null; if (parentContext instanceof JXPathContextReferenceImpl) { parentNR = ((JXPathContextReferenceImpl) parentContext).getNamespaceResolver(); } namespaceResolver = new NamespaceResolver(parentNR); namespaceResolver .setNamespaceContextPointer((NodePointer) this.contextPointer); } private static void createNodeFactoryArray() { if (nodeFactoryArray == null) { nodeFactoryArray = (NodePointerFactory[]) nodeFactories. toArray(new NodePointerFactory[nodeFactories.size()]); Arrays.sort(nodeFactoryArray, new

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> Comparator() { public int compare(Object a, Object b) { int orderA = ((NodePointerFactory) a).getOrder(); int orderB = ((NodePointerFactory) b).getOrder(); return orderA - orderB; } }); } } /** * Call this with a custom NodePointerFactory to add support for * additional types of objects. Make sure the factory returns * a name that puts it in the right position on the list of factories. */ public static void addNodePointerFactory(NodePointerFactory factory) { synchronized (nodeFactories) { nodeFactories.add(factory); nodeFactoryArray = null; } } public static NodePointerFactory[] getNodePointerFactories() { return nodeFactoryArray; } /** * Returns a static instance of TreeCompiler. * * Override this to return an aternate compiler. */ protected Compiler getCompiler() { return COMPILER; } protected CompiledExpression compilePath(String xpath) { return new JXPathCompiledExpression(xpath, compileExpression(xpath)); } private Expression compileExpression(String xpath) { Expression expr; synchronized (compiled) { if (USE_SOFT_CACHE) { expr = null; SoftReference ref = (SoftReference) compiled.get(xpath); if (ref != null) { expr = (Expression) ref.get(); } } else { expr = (Expression) compiled.get(xpath); } } if (expr != null) { return expr; } expr = (Expression) Parser.parseExpression(xpath, getCompiler()); synchronized (compiled) { if (USE_SOFT_CACHE) { if (cleanupCount++ >= CLEANUP_THRESHOLD) { Iterator it = compiled.entrySet().iterator(); while (it.hasNext()) { Entry me = (Entry) it.next(); if (((SoftReference) me.getValue()).get() == null) { it.remove(); } } cleanupCount = 0; } compiled.put(xpath, new SoftReference(expr)); } else { compiled.put(xpath, expr); } } return expr; } /** * Traverses the xpath and returns the resulting object. Primitive * types

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> return (Node)bean; // } // // if (bean instanceof Container) { // bean = ((Container)bean).getValue(); // return getNativeContextNode(bean); // } // // return null; // } public Object getValue(String xpath, Expression expr) { Object result = expr.computeValue(getEvalContext()); if (result == null) { if (expr instanceof Path) { if (!isLenient()) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } } return null; } if (result instanceof EvalContext) { EvalContext ctx = (EvalContext) result; result = ctx.getSingleNodePointer(); if (!isLenient() && result == null) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } } if (result instanceof NodePointer) { result = ((NodePointer) result).getValuePointer(); if (!isLenient() && !((NodePointer) result).isActual()) { // We need to differentiate between pointers representing // a non-existing property and ones representing a property // whose value is null. In the latter case, the pointer // is going to have isActual == false, but its parent, // which is a non-node pointer identifying the bean property, // will return isActual() == true. NodePointer parent = ((NodePointer) result).getImmediateParentPointer(); if (parent == null || !parent.isContainer() || !parent.isActual()) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } } result = ((NodePointer) result).getValue(); } return result; } /** * Calls getValue(xpath), converts the result to the required type * and returns the result of the conversion. */ public Object getValue(String xpath, Class requiredType) { Expression expr = compileExpression(xpath); return getValue(xpath, expr, requiredType); } public Object getValue(String xpath, Expression expr, Class requiredType) { Object value = getValue(xpath, expr); if (value != null && requiredType != null) { if (!TypeUtils.

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>canConvert(value, requiredType)) { throw new JXPathTypeConversionException( "Invalid expression type. '" + xpath + "' returns " + value.getClass().getName() + ". It cannot be converted to " + requiredType.getName()); } value = TypeUtils.convert(value, requiredType); } return value; } /** * Traverses the xpath and returns a Iterator of all results found * for the path. If the xpath matches no properties * in the graph, the Iterator will not be null. */ public Iterator iterate(String xpath) { return iterate(xpath, compileExpression(xpath)); } public Iterator iterate(String xpath, Expression expr) { return expr.iterate(getEvalContext()); } public Pointer getPointer(String xpath) { return getPointer(xpath, compileExpression(xpath)); } public Pointer getPointer(String xpath, Expression expr) { Object result = expr.computeValue(getEvalContext()); if (result instanceof EvalContext) { result = ((EvalContext) result).getSingleNodePointer(); } if (result instanceof Pointer) { if (!isLenient() && !((NodePointer) result).isActual()) { throw new JXPathNotFoundException("No pointer for xpath: " + xpath); } return (Pointer) result; } return NodePointer.newNodePointer(null, result, getLocale()); } public void setValue(String xpath, Object value) { setValue(xpath, compileExpression(xpath), value); } public void setValue(String xpath, Expression expr, Object value) { try { setValue(xpath, expr, value, false); } catch (Throwable ex) { throw new JXPathException( "Exception trying to set value with xpath " + xpath, ex); } } public Pointer createPath(String xpath) { return createPath(xpath, compileExpression(xpath)); } public Pointer createPath(String xpath, Expression expr) { try { Object result = expr.computeValue(getEvalContext()); Pointer pointer = null; if (result instanceof Pointer) { pointer = (Pointer) result; } else if (result instanceof EvalContext) { EvalContext ctx = (EvalContext) result; pointer =

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> ctx.getSingleNodePointer(); } else { checkSimplePath(expr); // This should never happen throw new JXPathException("Cannot create path:" + xpath); } return ((NodePointer) pointer).createPath(this); } catch (Throwable ex) { throw new JXPathException( "Exception trying to create xpath " + xpath, ex); } } public Pointer createPathAndSetValue(String xpath, Object value) { return createPathAndSetValue(xpath, compileExpression(xpath), value); } public Pointer createPathAndSetValue( String xpath, Expression expr, Object value) { try { return setValue(xpath, expr, value, true); } catch (Throwable ex) { throw new JXPathException( "Exception trying to create xpath " + xpath, ex); } } private Pointer setValue( String xpath, Expression expr, Object value, boolean create) { Object result = expr.computeValue(getEvalContext()); Pointer pointer = null; if (result instanceof Pointer) { pointer = (Pointer) result; } else if (result instanceof EvalContext) { EvalContext ctx = (EvalContext) result; pointer = ctx.getSingleNodePointer(); } else { if (create) { checkSimplePath(expr); } // This should never happen throw new JXPathException("Cannot set value for xpath: " + xpath); } if (create) { pointer = ((NodePointer) pointer).createPath(this, value); } else { pointer.setValue(value); } return pointer; } /** * Checks if the path follows the JXPath restrictions on the type * of path that can be passed to create... methods. */ private void checkSimplePath(Expression expr) { if (!(expr instanceof LocationPath) || !((LocationPath) expr).isSimplePath()) { throw new JXPathInvalidSyntaxException( "JXPath can only create a path if it uses exclusively " + "the child:: and attribute:: axes and has " + "no context-dependent predicates"); } } /** * Traverses the xpath and returns an Iterator of Pointers. * A Pointer provides easy access to

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> a property. * If the xpath matches no properties * in the graph, the Iterator be empty, but not null. */ public Iterator iteratePointers(String xpath) { return iteratePointers(xpath, compileExpression(xpath)); } public Iterator iteratePointers(String xpath, Expression expr) { return expr.iteratePointers(getEvalContext()); } public void removePath(String xpath) { removePath(xpath, compileExpression(xpath)); } public void removePath(String xpath, Expression expr) { try { NodePointer pointer = (NodePointer) getPointer(xpath, expr); if (pointer != null) { ((NodePointer) pointer).remove(); } } catch (Throwable ex) { throw new JXPathException( "Exception trying to remove xpath " + xpath, ex); } } public void removeAll(String xpath) { removeAll(xpath, compileExpression(xpath)); } public void removeAll(String xpath, Expression expr) { try { ArrayList list = new ArrayList(); Iterator it = expr.iteratePointers(getEvalContext()); while (it.hasNext()) { list.add(it.next()); } Collections.sort(list, ReverseComparator.INSTANCE); it = list.iterator(); if (it.hasNext()) { NodePointer pointer = (NodePointer) it.next(); pointer.remove(); while (it.hasNext()) { removePath(((NodePointer) it.next()).asPath()); } } } catch (Throwable ex) { throw new JXPathException( "Exception trying to remove all for xpath " + xpath, ex); } } public JXPathContext getRelativeContext(Pointer pointer) { Object contextBean = pointer.getNode(); if (contextBean == null) { throw new JXPathException( "Cannot create a relative context for a non-existent node: " + pointer); } return new JXPathContextReferenceImpl(this, contextBean, pointer); } public Pointer getContextPointer() { return contextPointer; } private NodePointer getAbsoluteRootPointer() { return (NodePointer) rootPointer; } private EvalContext getEvalContext() { return new InitialContext(new RootContext(this, (NodePointer)

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> getContextPointer())); } public EvalContext getAbsoluteRootContext() { return new InitialContext(new RootContext(this, getAbsoluteRootPointer())); } public NodePointer getVariablePointer(QName name) { String varName = name.toString(); JXPathContext varCtx = this; Variables vars = null; while (varCtx != null) { vars = varCtx.getVariables(); if (vars.isDeclaredVariable(varName)) { break; } varCtx = varCtx.getParentContext(); vars = null; } if (vars != null) { return new VariablePointer(vars, name); } else { // The variable is not declared, but we will create // a pointer anyway in case the user want to set, rather // than get, the value of the variable. return new VariablePointer(name); } } public Function getFunction(QName functionName, Object[] parameters) { String namespace = functionName.getPrefix(); String name = functionName.getName(); JXPathContext funcCtx = this; Function func = null; Functions funcs; while (funcCtx != null) { funcs = funcCtx.getFunctions(); if (funcs != null) { func = funcs.getFunction(namespace, name, parameters); if (func != null) { return func; } } funcCtx = funcCtx.getParentContext(); } throw new JXPathFunctionNotFoundException( "Undefined function: " + functionName.toString()); } public void registerNamespace(String prefix, String namespaceURI) { if (namespaceResolver.isSealed()) { namespaceResolver = (NamespaceResolver) namespaceResolver.clone(); } namespaceResolver.registerNamespace(prefix, namespaceURI); } public String getNamespaceURI(String prefix) { return namespaceResolver.getNamespaceURI(prefix); } /** * {@inheritDoc} * @see org.apache.commons.jxpath.JXPathContext#getPrefix(java.lang.String) */ public String getPrefix(String namespaceURI) { return namespaceResolver.getPrefix(namespaceURI); } public void setNamespaceContextPointer(Pointer pointer) { if (namespaceResolver.isSealed()) { namespaceResolver = (NamespaceResolver) namespaceResolver.

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.EvalContext; /** * An element of the compile tree holding a variable reference. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class VariableReference extends Expression { private QName varName; public VariableReference(QName varName) { this.varName = varName; } public QName getVariableName() { return varName; } public String toString() { return "$" + varName; } public boolean isContextDependent() { return false; } public boolean computeContextDependent() { return false; } public Object compute(EvalContext context) { return computeValue(context); } /** * Returns the value of the variable. */ public Object computeValue(EvalContext context) { return context.getRootContext().getVariableContext(varName); } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import org.apache.commons.jxpath.BasicNodeSet; import org.apache.commons.jxpath.ExpressionContext; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.axes.RootContext; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ReverseComparator; /** * An XPath evaluation context. * * When evaluating a path, a chain of EvalContexts is created, each context in * the chain representing a step of the path. Subclasses of EvalContext * implement behavior of various XPath axes: "child::", "parent::" etc. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public abstract class EvalContext implements ExpressionContext, Iterator { protected EvalContext parentContext; protected RootContext rootContext; protected int position = 0; private boolean startedSet

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>Iteration = false; private boolean done = false; private boolean hasPerformedIteratorStep = false; private Iterator pointerIterator; public EvalContext(EvalContext parentContext) { this.parentContext = parentContext; } public Pointer getContextNodePointer() { return getCurrentNodePointer(); } public JXPathContext getJXPathContext() { return getRootContext().getJXPathContext(); } public int getPosition() { return position; } /** * Determines the document order for this context. * * @return 1 ascending order, -1 descending order, * 0 - does not require ordering */ public int getDocumentOrder() { return parentContext != null && parentContext.isChildOrderingRequired() ? 1 : 0; } /** * Even if this context has the natural ordering and therefore does * not require collecting and sorting all nodes prior to returning them, * such operation may be required for any child context. */ public boolean isChildOrderingRequired() { // Default behavior: if this context needs to be ordered, // the children need to be ordered too return getDocumentOrder() != 0; } /** * Returns true if there are mode nodes matching the context's constraints. */ public boolean hasNext() { if (pointerIterator != null) { return pointerIterator.hasNext(); } if (getDocumentOrder() != 0) { return constructIterator(); } if (!done && !hasPerformedIteratorStep) { performIteratorStep(); } return !done; } /** * Returns the next node pointer in the context */ public Object next() { if (pointerIterator != null) { return pointerIterator.next(); } if (getDocumentOrder() != 0) { if (!constructIterator()) { throw new NoSuchElementException(); } return pointerIterator.next(); } if (!done && !hasPerformedIteratorStep) { performIteratorStep(); } if (done) { throw new NoSuchElementException(); } hasPerformedIteratorStep = false; return getCurrentNodePointer(); } /** * Moves the iterator forward by one position */ private void performIteratorStep() { done = true; if (position != 0 && nextNode()) {

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> done = false; } else { while (nextSet()) { if (nextNode()) { done = false; break; } } } hasPerformedIteratorStep = true; } /** * Operation is not supported */ public void remove() { throw new UnsupportedOperationException( "JXPath iterators cannot remove nodes"); } private boolean constructIterator() { HashSet set = new HashSet(); ArrayList list = new ArrayList(); while (nextSet()) { while (nextNode()) { NodePointer pointer = getCurrentNodePointer(); if (!set.contains(pointer)) { set.add(pointer); list.add(pointer); } } } if (list.isEmpty()) { return false; } if (getDocumentOrder() == 1) { Collections.sort(list); } else { Collections.sort(list, ReverseComparator.INSTANCE); } pointerIterator = list.iterator(); return true; } /** * Returns the list of all Pointers in this context for the current * position of the parent context. */ public List getContextNodeList() { int pos = position; if (pos != 0) { reset(); } List list = new ArrayList(); while (nextNode()) { list.add(getCurrentNodePointer()); } if (pos != 0) { setPosition(pos); } else { reset(); } return list; } /** * Returns the list of all Pointers in this context for all positions * of the parent contexts. If there was an ongoing iteration over * this context, the method should not be called. */ public NodeSet getNodeSet() { if (position != 0) { throw new JXPathException( "Simultaneous operations: " + "should not request pointer list while " + "iterating over an EvalContext"); } BasicNodeSet set = new BasicNodeSet(); while (nextSet()) { while (nextNode()) { set.add((Pointer)getCurrentNodePointer().clone()); } } return set; } /** * Typically returns the NodeSet by calling getNodeSet(), * but will be overridden for contexts that more naturally produce * individual values, e

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>.g. VariableContext */ public Object getValue() { return getNodeSet(); } public String toString() { Pointer ptr = getContextNodePointer(); return ptr == null ? "Empty expression context" : "Expression context [" + getPosition() + "] " + ptr.asPath(); } /** * Returns the root context of the path, which provides easy * access to variables and functions. */ public RootContext getRootContext() { if (rootContext == null) { rootContext = parentContext.getRootContext(); } return rootContext; } /** * Sets current position = 0, which is the pre-iteration state. */ public void reset() { position = 0; } public int getCurrentPosition() { return position; } /** * Returns the first encountered Pointer that matches the current * context's criteria. */ public Pointer getSingleNodePointer() { reset(); while (nextSet()) { if (nextNode()) { return getCurrentNodePointer(); } } return null; } /** * Returns the current context node. Undefined before the beginning * of the iteration. */ public abstract NodePointer getCurrentNodePointer(); /** * Returns true if there is another sets of objects to interate over. * Resets the current position and node. */ public boolean nextSet() { reset(); // Restart iteration within the set // Most of the time you have one set per parent node // First time this method is called, we should look for // the first parent set that contains at least one node. if (!startedSetIteration) { startedSetIteration = true; while (parentContext.nextSet()) { if (parentContext.nextNode()) { return true; } } return false; } // In subsequent calls, we see if the parent context // has any nodes left in the current set if (parentContext.nextNode()) { return true; } // If not, we look for the next set that contains // at least one node while (parentContext.nextSet()) { if (parentContext.nextNode()) { return true; } } return false; } /** * Returns true if there is another object in the current

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * A compile tree element containing a constant number or string. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class Constant extends Expression { private Object value; public Constant(Number number) { this.value = number; } public Constant(String string) { this.value = string; } public Object compute(EvalContext context) { return value; } /** * Returns the value of the constant. */ public Object computeValue(EvalContext context) { return value; } /** * Returns false */ public boolean isContextDependent() { return false; } /** * Returns false */ public boolean computeContextDependent() { return false; } public String toString() { if (value instanceof Number) { return InfoSetUtil.stringValue(value); } return "'" + value + "'"; } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> points to a DOM node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class JDOMNodePointer extends NodePointer { private static final long serialVersionUID = -6346532297491082651L; private Object node; private String id; public static final String XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace"; public static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/"; public JDOMNodePointer(Object node, Locale locale) { super(null, locale); this.node = node; } public JDOMNodePointer(Object node, Locale locale, String id) { super(null, locale); this.node = node; this.id = id; } public JDOMNodePointer(NodePointer parent, Object node) { super(parent); this.node = node; } public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { return new JDOMNodeIterator(this, test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new JDOMAttributeIterator(this, name); } public NodeIterator namespaceIterator() { return new JDOMNamespaceIterator(this); } public NodePointer namespacePointer(String prefix) { return new JDOMNamespacePointer(this, prefix); } public String getNamespaceURI() { return getNamespaceURI(node); } private static String getNamespaceURI(Object node) { if (node instanceof Element) { Element element = (Element) node; String ns = element.getNamespaceURI(); if (ns != null && ns.equals("")) { ns = null; } return ns; } return null; } public String getNamespaceURI(String prefix) { if (node instanceof Document) { Element element = ((Document)node).getRootElement(); Namespace ns = element.getNamespace(prefix); if (ns != null) { return ns.getURI(); } } else if (node

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> instanceof Element) { Element element = (Element) node; Namespace ns = element.getNamespace(prefix); if (ns != null) { return ns.getURI(); } } return null; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { Object node1 = pointer1.getBaseValue(); Object node2 = pointer2.getBaseValue(); if (node1 == node2) { return 0; } if ((node1 instanceof Attribute) && !(node2 instanceof Attribute)) { return -1; } if ( !(node1 instanceof Attribute) && (node2 instanceof Attribute)) { return 1; } if ( (node1 instanceof Attribute) && (node2 instanceof Attribute)) { List list = ((Element) getNode()).getAttributes(); int length = list.size(); for (int i = 0; i < length; i++) { Object n = list.get(i); if (n == node1) { return -1; } else if (n == node2) { return 1; } } return 0; // Should not happen } if (!(node instanceof Element)) { throw new RuntimeException( "JXPath internal error: " + "compareChildNodes called for " + node); } List children = ((Element) node).getContent(); int length = children.size(); for (int i = 0; i < length; i++) { Object n = children.get(i); if (n == node1) { return -1; } if (n == node2) { return 1; } } return 0; } /** * @see org.apache.commons.jxpath.ri.model.NodePointer#getBaseValue() */ public Object getBaseValue() { return node; } public boolean isCollection() { return false; } public int getLength() { return 1; } public boolean isLeaf() { if (node instanceof Element) { return ((Element) node).getContent().size() == 0; } if (node instanceof Document) { return ((Document) node).getContent().size() ==

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> 0; } return true; } /** * @see org.apache.commons.jxpath.ri.model.NodePointer#getName() */ public QName getName() { String ns = null; String ln = null; if (node instanceof Element) { ns = ((Element) node).getNamespacePrefix(); if (ns != null && ns.equals("")) { ns = null; } ln = ((Element) node).getName(); } else if (node instanceof ProcessingInstruction) { ln = ((ProcessingInstruction) node).getTarget(); } return new QName(ns, ln); } /** * @see org.apache.commons.jxpath.ri.model.NodePointer#getNode() */ public Object getImmediateNode() { return node; } public Object getValue() { if (node instanceof Element) { StringBuffer buf = new StringBuffer(); for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) { NodePointer ptr = children.getNodePointer(); if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) { buf.append(ptr.getValue()); } } return buf.toString(); } if (node instanceof Comment) { String text = ((Comment) node).getText(); if (text != null) { text = text.trim(); } return text; } String result = null; if (node instanceof Text) { result = ((Text) node).getText(); } if (node instanceof ProcessingInstruction) { result = ((ProcessingInstruction) node).getData(); } boolean trim = !"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE)); return result != null && trim ? result.trim() : result; } public void setValue(Object value) { if (node instanceof Text) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { ((Text) node).setText(string); } else { nodeParent(node).removeContent((Text) node); } } else { Element element = (Element) node;

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> element.getContent().clear(); if (value instanceof Element) { Element valueElement = (Element) value; addContent(valueElement.getContent()); } else if (value instanceof Document) { Document valueDocument = (Document) value; addContent(valueDocument.getContent()); } else if (value instanceof Text || value instanceof CDATA) { String string = ((Text) value).getText(); element.addContent(new Text(string)); } else if (value instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction) ((ProcessingInstruction) value) .clone(); element.addContent(pi); } else if (value instanceof Comment) { Comment comment = (Comment) ((Comment) value).clone(); element.addContent(comment); } else { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { element.addContent(new Text(string)); } } } } private void addContent(List content) { Element element = (Element) node; int count = content.size(); for (int i = 0; i < count; i++) { Object child = content.get(i); if (child instanceof Element) { child = ((Element) child).clone(); element.addContent((Element) child); } else if (child instanceof Text) { child = ((Text) child).clone(); element.addContent((Text) child); } else if (node instanceof CDATA) { child = ((CDATA) child).clone(); element.addContent((CDATA) child); } else if (node instanceof ProcessingInstruction) { child = ((ProcessingInstruction) child).clone(); element.addContent((ProcessingInstruction) child); } else if (node instanceof Comment) { child = ((Comment) child).clone(); element.addContent((Comment) child); } } } public boolean testNode(NodeTest test) { return testNode(this, node, test); } public static boolean testNode( NodePointer pointer, Object node, NodeTest test) { if (test == null) { return true; } if (

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> null ? null : context .getNamespaceURI(prefix); nodeTest = new NodeNameTest(name, namespaceURI); NodeIterator it = childIterator(nodeTest, false, null); if (it != null && it.setPosition(index + 1)) { return it.getNodePointer(); } } throw new JXPathAbstractFactoryException("Factory could not create " + "a child node for path: " + asPath() + "/" + name + "[" + (index + 1) + "]"); } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { NodePointer ptr = createChild(context, name, index); ptr.setValue(value); return ptr; } public NodePointer createAttribute(JXPathContext context, QName name) { if (!(node instanceof Element)) { return super.createAttribute(context, name); } Element element = (Element) node; String prefix = name.getPrefix(); if (prefix != null) { Namespace ns = element.getNamespace(prefix); if (ns == null) { throw new JXPathException( "Unknown namespace prefix: " + prefix); } Attribute attr = element.getAttribute(name.getName(), ns); if (attr == null) { element.setAttribute(name.getName(), "", ns); } } else { Attribute attr = element.getAttribute(name.getName()); if (attr == null) { element.setAttribute(name.getName(), ""); } } NodeIterator it = attributeIterator(name); it.setPosition(1); return it.getNodePointer(); } public void remove() { Element parent = nodeParent(node); if (parent == null) { throw new JXPathException("Cannot remove root JDOM node"); } parent.getContent().remove(node); } public String asPath() { if (id != null) { return "id('" + escape(id) + "')"; } StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); } if (node instanceof Element) { // If the parent pointer is not a JDOMNodePointer, it is // the parent's responsibility

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that returns the current node from the parent context if the * test succeeds. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class SelfContext extends EvalContext { private NodeTest nodeTest; private boolean startedSet = false; private NodePointer nodePointer; public SelfContext(EvalContext parentContext, NodeTest nodeTest) { super(parentContext); this.nodeTest = nodeTest; } public Pointer getSingleNodePointer() { return parentContext.getSingleNodePointer(); } public NodePointer getCurrentNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } } return nodePointer; } public boolean nextNode() { return setPosition(getCurrentPosition() + 1); } public void reset() { super.reset(); startedSet = false; } public boolean setPosition(int position) { if (position != 1) { return false; } super.setPosition(position); if (!

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Set; import junit.framework.TestCase; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Abstract superclass for various JXPath tests. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public abstract class JXPathTestCase extends TestCase { /** * Construct a new instance of this test case. * * @param name Name of the test case */ public JXPathTestCase(String name) { super(name); Locale.setDefault(Locale.US); } protected void assertXPathValue(JXPathContext ctx, String xpath, Object expected) { ctx.setLenient(false); Object actual = ctx.getValue(xpath); assertEquals("Evaluating <" + xpath + ">", expected, actual); } protected void assertXPathValue(JXPathContext ctx, String xpath, Object expected, Class resultType) { ctx.setLenient(false); Object actual = ctx.getValue(xpath, resultType); assertEquals("Evaluating <" + xpath + ">", expected, actual); } protected void assertXPath

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>ValueLenient(JXPathContext ctx, String xpath, Object expected) { ctx.setLenient(true); Object actual = ctx.getValue(xpath); ctx.setLenient(false); assertEquals("Evaluating lenient <" + xpath + ">", expected, actual); } protected void assertXPathSetValue(JXPathContext ctx, String xpath, Object value) { assertXPathSetValue(ctx, xpath, value, value); } protected void assertXPathSetValue(JXPathContext ctx, String xpath, Object value, Object expected) { ctx.setValue(xpath, value); Object actual = ctx.getValue(xpath); assertEquals("Modifying <" + xpath + ">", expected, actual); } protected void assertXPathCreatePath(JXPathContext ctx, String xpath, Object expectedValue, String expectedPath) { Pointer pointer = ctx.createPath(xpath); assertEquals("Creating path <" + xpath + ">", expectedPath, pointer.asPath()); assertEquals("Creating path (pointer value) <" + xpath + ">", expectedValue, pointer.getValue()); assertEquals("Creating path (context value) <" + xpath + ">", expectedValue, ctx.getValue(pointer.asPath())); } protected void assertXPathCreatePathAndSetValue(JXPathContext ctx, String xpath, Object value, String expectedPath) { Pointer pointer = ctx.createPathAndSetValue(xpath, value); assertEquals("Creating path <" + xpath + ">", expectedPath, pointer.asPath()); assertEquals("Creating path (pointer value) <" + xpath + ">", value, pointer.getValue()); assertEquals("Creating path (context value) <" + xpath + ">", value, ctx.getValue(pointer.asPath())); } protected void assertXPathPointer(JXPathContext ctx, String xpath, String expected) { ctx.setLenient(false); Pointer pointer = ctx.getPointer(xpath); String actual = pointer.toString(); assertEquals("Evaluating pointer <" + xpath + ">", expected, actual); } protected void assertXPathPointerLenient(JXPathContext ctx, String xpath, String expected) { ctx.setLenient(true); Pointer pointer = ctx.getPointer(xpath); String

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> actual = pointer.toString(); assertEquals("Evaluating pointer <" + xpath + ">", expected, actual); } protected void assertXPathValueAndPointer(JXPathContext ctx, String xpath, Object expectedValue, String expectedPointer) { assertXPathValue(ctx, xpath, expectedValue); assertXPathPointer(ctx, xpath, expectedPointer); } protected void assertXPathValueIterator(JXPathContext ctx, String xpath, Collection expected) { Collection actual; if (expected instanceof List) { actual = new ArrayList(); } else { actual = new HashSet(); } Iterator it = ctx.iterate(xpath); while (it.hasNext()) { actual.add(it.next()); } assertEquals("Evaluating value iterator <" + xpath + ">", expected, actual); } protected void assertXPathPointerIterator( JXPathContext ctx, String xpath, Collection expected) { Collection actual; if (expected instanceof List) { actual = new ArrayList(); } else { actual = new HashSet(); } Iterator it = ctx.iteratePointers(xpath); while (it.hasNext()) { Pointer pointer = (Pointer) it.next(); actual.add(pointer.toString()); } assertEquals( "Evaluating pointer iterator <" + xpath + ">", expected, actual); } protected void assertDocumentOrder( JXPathContext context, String path1, String path2, int expected) { NodePointer np1 = (NodePointer) context.getPointer(path1); NodePointer np2 = (NodePointer) context.getPointer(path2); int res = np1.compareTo(np2); if (res < 0) { res = -1; } else if (res > 0) { res = 1; } assertEquals( "Comparing paths '" + path1 + "' and '" + path2 + "'", expected, res); } protected void assertXPathValueType( JXPathContext ctx, String xpath, Class clazz) { ctx.setLenient(false); Object actual = ctx.getValue(xpath); assertTrue("Evaluating <" + xpath + "> = " + actual.getClass(), clazz.isAssignableFrom(actual

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>.getClass())); } protected void assertXPathNodeType( JXPathContext ctx, String xpath, Class clazz) { ctx.setLenient(false); Pointer actual = ctx.getPointer(xpath); assertTrue("Evaluating <" + xpath + "> = " + actual.getNode().getClass(), clazz.isAssignableFrom(actual.getNode().getClass())); } protected static List list() { return Collections.EMPTY_LIST; } protected static List list(Object o1) { List list = new ArrayList(); list.add(o1); return list; } protected static List list(Object o1, Object o2) { List list = new ArrayList(); list.add(o1); list.add(o2); return list; } protected static List list(Object o1, Object o2, Object o3) { List list = new ArrayList(); list.add(o1); list.add(o2); list.add(o3); return list; } protected static Set set(Object o1, Object o2, Object o3) { Set list = new HashSet(); list.add(o1); list.add(o2); list.add(o3); return list; } protected static List list(Object o1, Object o2, Object o3, Object o4) { List list = new ArrayList(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); return list; } protected static Set set(Object o1, Object o2, Object o3, Object o4) { Set list = new HashSet(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); return list; } protected static List list(Object o1, Object o2, Object o3, Object o4, Object o5) { List list = new ArrayList(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); return list; } protected static Set set

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>(Object o1, Object o2, Object o3, Object o4, Object o5) { Set list = new HashSet(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); return list; } protected static List list(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6) { List list = new ArrayList(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); list.add(o6); return list; } protected static Set set(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6) { Set list = new HashSet(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); list.add(o6); return list; } protected static List list(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7) { List list = new ArrayList(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); list.add(o6); list.add(o7); return list; } protected static Set set(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7) { Set list = new HashSet(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); list.add(o6); list.add(o7); return list; } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Namespace resolver for JXPathContextReferenceImpl. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class NamespaceResolver implements Cloneable { final protected NamespaceResolver parent; protected HashMap namespaceMap = new HashMap(); protected HashMap reverseMap; protected NodePointer pointer; private boolean sealed; /** * Create a new NamespaceResolver. */ public NamespaceResolver() { this(null); } /** * Create a new NamespaceResolver. * @param parent */ public NamespaceResolver(NamespaceResolver parent) { this.parent = parent; } /** * Registers a namespace prefix. * * @param prefix A namespace prefix * @param namespaceURI A URI for that prefix */ public synchronized void registerNamespace(String prefix, String namespaceURI) { if (isSealed()) { throw new IllegalStateException("Cannot register namespaces on a sealed NamespaceResolver"); } namespaceMap.put(prefix, namespaceURI); reverseMap = null; } /** * Register a namespace for the expression context.

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> * @param pointer the Pointer to set. */ public void setNamespaceContextPointer(NodePointer pointer) { this.pointer = pointer; } /** * Get the namespace context pointer. * @return Pointer */ public Pointer getNamespaceContextPointer() { if (pointer == null && parent != null) { return parent.getNamespaceContextPointer(); } return pointer; } /** * Given a prefix, returns a registered namespace URI. If the requested * prefix was not defined explicitly using the registerNamespace method, * JXPathContext will then check the context node to see if the prefix is * defined there. See * {@link #setNamespaceContextPointer(NodePointer) setNamespaceContextPointer}. * * @param prefix The namespace prefix to look up * @return namespace URI or null if the prefix is undefined. */ public synchronized String getNamespaceURI(String prefix) { String uri = (String) namespaceMap.get(prefix); if (uri == null && pointer != null) { uri = pointer.getNamespaceURI(prefix); } if (uri == null && parent != null) { return parent.getNamespaceURI(prefix); } return uri; } /** * Get the prefix associated with the specifed namespace URI. * @param namespaceURI the ns URI to check. * @return String prefix */ public synchronized String getPrefix(String namespaceURI) { if (reverseMap == null) { reverseMap = new HashMap(); NodeIterator ni = pointer.namespaceIterator(); if (ni != null) { for (int position = 1; ni.setPosition(position); position++) { NodePointer nsPointer = ni.getNodePointer(); String uri = nsPointer.getNamespaceURI(); String prefix = nsPointer.getName().getName(); if (!"".equals(prefix)) { reverseMap.put(uri, prefix); } } } Iterator it = namespaceMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); reverseMap.put(entry.getValue(), entry.getKey()); } } String prefix = (String) reverseMap.get(namespaceURI); if (prefix == null && parent != null) {

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.container; import java.util.Locale; import org.apache.commons.jxpath.Container; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Transparent pointer to a Container. The getValue() method * returns the contents of the container, rather than the container * itself. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class ContainerPointer extends NodePointer { private Container container; private NodePointer valuePointer; public ContainerPointer(Container container, Locale locale) { super(null, locale); this.container = container; } public ContainerPointer(NodePointer parent, Container container) { super(parent); this.container = container; } /** * This type of node is auxiliary. */ public boolean isContainer() { return true; } public QName getName() { return null; } public Object getBaseValue() { return container; } public boolean isCollection() { Object value = getBaseValue(); return value != null &&

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> ValueUtils.isCollection(value); } public int getLength() { Object value = getBaseValue(); return value == null ? 1 : ValueUtils.getLength(value); } public boolean isLeaf() { return getValuePointer().isLeaf(); } public Object getImmediateNode() { Object value = getBaseValue(); if (index != WHOLE_COLLECTION) { return index >= 0 && index < getLength() ? ValueUtils.getValue(value, index) : null; } return ValueUtils.getValue(value); } public void setValue(Object value) { // TODO: what if this is a collection? container.setValue(value); } public NodePointer getImmediateValuePointer() { if (valuePointer == null) { Object value = getImmediateNode(); valuePointer = NodePointer.newChildNodePointer(this, getName(), value); } return valuePointer; } public int hashCode() { return System.identityHashCode(container) + index; } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof ContainerPointer)) { return false; } ContainerPointer other = (ContainerPointer) object; return container == other.container && index == other.index; } public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { return getValuePointer().childIterator(test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return getValuePointer().attributeIterator(name); } public NodeIterator namespaceIterator() { return getValuePointer().namespaceIterator(); } public NodePointer namespacePointer(String namespace) { return getValuePointer().namespacePointer(namespace); } public boolean testNode(NodeTest nodeTest) { return getValuePointer().testNode(nodeTest); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { return pointer1.getIndex() - pointer2.getIndex(); } public String getNamespaceURI(String prefix) { return getValuePointer().getNamespaceURI(prefix); } public String asPath() { return parent == null ? "/" : parent.asPath(); } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.axes.AncestorContext; import org.apache.commons.jxpath.ri.axes.AttributeContext; import org.apache.commons.jxpath.ri.axes.ChildContext; import org.apache.commons.jxpath.ri.axes.DescendantContext; import org.apache.commons.jxpath.ri.axes.InitialContext; import org.apache.commons.jxpath.ri.axes.NamespaceContext; import org.apache.commons.jxpath.ri.axes.ParentContext; import org.apache.commons.jxpath.ri.axes.PrecedingOrFollowingContext; import org.apache.commons.jxpath.ri.axes.PredicateContext; import org.apache.commons.jxpath.ri.axes.SelfContext; import org.apache.commons.jxpath.ri.axes.SimplePathInterpreter; import org.apache.commons.jxpath.ri.axes.UnionContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * @author Dmitri Plotnikov *

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>step.getPredicates()); } return false; } protected boolean areBasicPredicates(Expression predicates[]) { if (predicates != null && predicates.length != 0) { boolean firstIndex = true; for (int i = 0; i < predicates.length; i++) { if (predicates[i] instanceof NameAttributeTest) { if (((NameAttributeTest) predicates[i]) .getNameTestExpression() .isContextDependent()) { return false; } } else if (predicates[i].isContextDependent()) { return false; } else { if (!firstIndex) { return false; } firstIndex = false; } } } return true; } /** * Given a root context, walks a path therefrom and finds the * pointer to the first element matching the path. */ protected Pointer getSingleNodePointerForSteps(EvalContext context) { if (steps.length == 0) { return context.getSingleNodePointer(); } if (isSimplePath()) { NodePointer ptr = (NodePointer) context.getSingleNodePointer(); return SimplePathInterpreter.interpretSimpleLocationPath( context, ptr, steps); } return searchForPath(context); } /** * The idea here is to return a NullPointer rather than null if that's at * all possible. Take for example this path: "//map/key". Let's say, "map" * is an existing node, but "key" is not there. We will create a * NullPointer that can be used to set/create the "key" property. * <p> * However, a path like "//key" would still produce null, because we have * no way of knowing where "key" would be if it existed. * </p> * <p> * To accomplish this, we first try the path itself. If it does not find * anything, we chop off last step of the path, as long as it is a simple * one like child:: or attribute:: and try to evaluate the truncated path. * If it finds exactly one node - create a NullPointer and return. If it * fails, chop off another step and repeat. If it finds more than one

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> * location - return null. * </p> */ private Pointer searchForPath(EvalContext context) { EvalContext ctx = buildContextChain(context, steps.length, true); Pointer pointer = ctx.getSingleNodePointer(); if (pointer != null) { return pointer; } for (int i = steps.length; --i > 0;) { if (!isSimpleStep(steps[i])) { return null; } ctx = buildContextChain(context, i, true); if (ctx.hasNext()) { Pointer partial = (Pointer) ctx.next(); if (ctx.hasNext()) { // If we find another location - the search is // ambiguous, so we report failure return null; } if (partial instanceof NodePointer) { return SimplePathInterpreter.createNullPointer( context, (NodePointer) partial, steps, i); } } } return null; } /** * Given a root context, walks a path therefrom and builds a context * that contains all nodes matching the path. */ protected EvalContext evalSteps(EvalContext context) { return buildContextChain(context, steps.length, false); } private EvalContext buildContextChain( EvalContext context, int stepCount, boolean createInitialContext) { if (createInitialContext) { context = new InitialContext(context); } if (steps.length == 0) { return context; } for (int i = 0; i < stepCount; i++) { context = createContextForStep( context, steps[i].getAxis(), steps[i].getNodeTest()); Expression predicates[] = steps[i].getPredicates(); if (predicates != null) { for (int j = 0; j < predicates.length; j++) { if (j != 0) { context = new UnionContext(context, new EvalContext[]{context}); } context = new PredicateContext(context, predicates[j]); } } } return context; } /** * Different axes are serviced by different contexts. This method * allocates the right context for the supplied step. */ protected EvalContext createContextForStep(

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> EvalContext context, int axis, NodeTest nodeTest) { if (nodeTest instanceof NodeNameTest) { QName qname = ((NodeNameTest) nodeTest).getNodeName(); String prefix = qname.getPrefix(); if (prefix != null) { String namespaceURI = context.getJXPathContext() .getNamespaceURI(prefix); nodeTest = new NodeNameTest(qname, namespaceURI); } } switch (axis) { case Compiler.AXIS_ANCESTOR : return new AncestorContext(context, false, nodeTest); case Compiler.AXIS_ANCESTOR_OR_SELF : return new AncestorContext(context, true, nodeTest); case Compiler.AXIS_ATTRIBUTE : return new AttributeContext(context, nodeTest); case Compiler.AXIS_CHILD : return new ChildContext(context, nodeTest, false, false); case Compiler.AXIS_DESCENDANT : return new DescendantContext(context, false, nodeTest); case Compiler.AXIS_DESCENDANT_OR_SELF : return new DescendantContext(context, true, nodeTest); case Compiler.AXIS_FOLLOWING : return new PrecedingOrFollowingContext(context, nodeTest, false); case Compiler.AXIS_FOLLOWING_SIBLING : return new ChildContext(context, nodeTest, true, false); case Compiler.AXIS_NAMESPACE : return new NamespaceContext(context, nodeTest); case Compiler.AXIS_PARENT : return new ParentContext(context, nodeTest); case Compiler.AXIS_PRECEDING : return new PrecedingOrFollowingContext(context, nodeTest, true); case Compiler.AXIS_PRECEDING_SIBLING : return new ChildContext(context, nodeTest, true, true); case Compiler.AXIS_SELF : return new SelfContext(context, nodeTest); } return null; // Never happens } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class NullPointer extends PropertyOwnerPointer { private QName name; private String id; public NullPointer(QName name, Locale locale) { super(null, locale); this.name = name; } /** * Used for the root node */ public NullPointer(NodePointer parent, QName name) { super(parent); this.name = name; } public NullPointer(Locale locale, String id) { super(null, locale); this.id = id; } public QName getName() { return name; } public Object getBaseValue() { return null; } public boolean isCollection() { return false; } public boolean isLeaf() { return true; } public boolean isActual() { return false; } public PropertyPointer getPropertyPointer() { return new NullPropertyPointer(this); } public NodePointer createPath(JXPathContext context, Object value) { if (parent != null) { return parent.createPath(context,

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> value).getValuePointer(); } throw new UnsupportedOperationException( "Cannot create the root object: " + asPath()); } public NodePointer createPath(JXPathContext context) { if (parent != null) { return parent.createPath(context).getValuePointer(); } throw new UnsupportedOperationException( "Cannot create the root object: " + asPath()); } public NodePointer createChild( JXPathContext context, QName name, int index) { return createPath(context).createChild(context, name, index); } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { return createPath(context).createChild(context, name, index, value); } public int hashCode() { return name == null ? 0 : name.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof NullPointer)) { return false; } NullPointer other = (NullPointer) object; return name == other.name || name != null && name.equals(other.name); } public String asPath() { if (id != null) { return "id(" + id + ")"; } return parent == null ? "null()" : super.asPath(); } public int getLength() { return 0; } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.beans.IndexedPropertyDescriptor; import java.beans.PropertyDescriptor; import org.apache.commons.jxpath.JXPathBeanInfo; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Pointer pointing to a property of a JavaBean. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class BeanPropertyPointer extends PropertyPointer { private String propertyName; private JXPathBeanInfo beanInfo; private PropertyDescriptor propertyDescriptors[]; private PropertyDescriptor propertyDescriptor; private String[] names; private static final Object UNINITIALIZED = new Object(); private Object baseValue = UNINITIALIZED; private Object value = UNINITIALIZED; public BeanPropertyPointer(NodePointer parent, JXPathBeanInfo beanInfo) { super(parent); this.beanInfo = beanInfo; } /** * This type of node is auxiliary. */ public boolean isContainer() { return true; } /** * Number of the bean's properties. */ public int getPropertyCount() { if (beanInfo.isAtomic()) { return 0; }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> return getPropertyDescriptors().length; } /** * Names of all properties, sorted alphabetically */ public String[] getPropertyNames() { if (names == null) { PropertyDescriptor pds[] = getPropertyDescriptors(); names = new String[pds.length]; for (int i = 0; i < names.length; i++) { names[i] = pds[i].getName(); } } return names; } /** * Select a property by name */ public void setPropertyName(String propertyName) { setPropertyIndex(UNSPECIFIED_PROPERTY); this.propertyName = propertyName; } /** * Selects a property by its offset in the alphabetically sorted list. */ public void setPropertyIndex(int index) { if (propertyIndex != index) { super.setPropertyIndex(index); propertyName = null; propertyDescriptor = null; baseValue = UNINITIALIZED; value = UNINITIALIZED; } } /** * The value of the currently selected property. */ public Object getBaseValue() { if (baseValue == UNINITIALIZED) { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { return null; } baseValue = ValueUtils.getValue(getBean(), pd); } return baseValue; } public void setIndex(int index) { if (this.index != index) { // When dealing with a scalar, index == 0 is equivalent to // WHOLE_COLLECTION, so do not change it. if (this.index != WHOLE_COLLECTION || index != 0 || isCollection()) { super.setIndex(index); value = UNINITIALIZED; } } } /** * If index == WHOLE_COLLECTION, the value of the property, otherwise * the value of the index'th element of the collection represented by the * property. If the property is not a collection, index should be zero * and the value will be the property itself. */ public Object getImmediateNode() { if (value == UNINITIALIZED) { if (index == WHOLE_COLLECTION) { value = ValueUtils.getValue(getBaseValue()); } else { PropertyDescriptor pd = getPropertyDescriptor(); if

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> (pd == null) { value = null; } else { value = ValueUtils.getValue(getBean(), pd, index); } } } return value; } protected boolean isActualProperty() { return getPropertyDescriptor() != null; } public boolean isCollection() { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { return false; } if (pd instanceof IndexedPropertyDescriptor) { return true; } int hint = ValueUtils.getCollectionHint(pd.getPropertyType()); if (hint == -1) { return false; } if (hint == 1) { return true; } Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); } /** * If the property contains a collection, then the length of that * collection, otherwise - 1. */ public int getLength() { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { return 1; } if (pd instanceof IndexedPropertyDescriptor) { return ValueUtils.getIndexedPropertyLength( getBean(), (IndexedPropertyDescriptor) pd); } int hint = ValueUtils.getCollectionHint(pd.getPropertyType()); if (hint == -1) { return 1; } return ValueUtils.getLength(getBaseValue()); } /** * If index == WHOLE_COLLECTION, change the value of the property, otherwise * change the value of the index'th element of the collection * represented by the property. */ public void setValue(Object value) { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { throw new JXPathInvalidAccessException( "Cannot set property: " + asPath() + " - no such property"); } if (index == WHOLE_COLLECTION) { ValueUtils.setValue(getBean(), pd, value); } else { ValueUtils.setValue(getBean(), pd, index, value); } this.value = value; } /** * @see PropertyPointer#createPath(JXPathContext) */ public NodePointer createPath(JXPathContext context) { if (getImmediateNode() == null) { super.createPath(

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>context); baseValue = UNINITIALIZED; value = UNINITIALIZED; } return this; } public void remove() { if (index == WHOLE_COLLECTION) { setValue(null); } else if (isCollection()) { Object o = getBaseValue(); Object collection = ValueUtils.remove(getBaseValue(), index); if (collection != o) { ValueUtils.setValue(getBean(), getPropertyDescriptor(), collection); } } else if (index == 0) { index = WHOLE_COLLECTION; setValue(null); } } /** * Name of the currently selected property. */ public String getPropertyName() { if (propertyName == null) { PropertyDescriptor pd = getPropertyDescriptor(); if (pd != null) { propertyName = pd.getName(); } } return propertyName != null ? propertyName : "*"; } /** * Finds the property descriptor corresponding to the current property * index. */ private PropertyDescriptor getPropertyDescriptor() { if (propertyDescriptor == null) { int inx = getPropertyIndex(); if (inx == UNSPECIFIED_PROPERTY) { propertyDescriptor = beanInfo.getPropertyDescriptor(propertyName); } else { PropertyDescriptor propertyDescriptors[] = getPropertyDescriptors(); if (inx >= 0 && inx < propertyDescriptors.length) { propertyDescriptor = propertyDescriptors[inx]; } else { propertyDescriptor = null; } } } return propertyDescriptor; } protected PropertyDescriptor[] getPropertyDescriptors() { if (propertyDescriptors == null) { propertyDescriptors = beanInfo.getPropertyDescriptors(); } return propertyDescriptors; } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.Iterator; import java.util.Map; import java.util.Set; /** * Implements the DynamicPropertyHandler interface for java.util.Map. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class MapDynamicPropertyHandler implements DynamicPropertyHandler { /** * Returns string representations of all keys in the map. */ public String[] getPropertyNames(Object object) { Map map = (Map) object; Set set = map.keySet(); String names[] = new String[set.size()]; Iterator it = set.iterator(); for (int i = 0; i < names.length; i++) { names[i] = String.valueOf(it.next()); } return names; } /** * Returns the value for the specified key. */ public Object getProperty(Object object, String propertyName) { return ((Map) object).get(propertyName); } /** * Sets the specified key value. */ public void setProperty(Object object, String propertyName, Object value) { ((Map) object).put(propertyName, value); } }

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.HashSet; import java.util.Locale; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl; import org.apache.commons.jxpath.ri.NamespaceResolver; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.beans.NullPointer; /** * Common superclass for Pointers of all kinds. A NodePointer maps to * a deterministic XPath that represents the location of a node in an * object graph. This XPath uses only simple axes: child, namespace and * attribute and only simple, context-independent predicates. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public abstract class NodePointer implements Pointer { public static final int WHO

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS>In JavaBeans) if <em>address</em> is not a property of the root bean, * a Pointer for this path cannot be obtained at all - actual or otherwise. */ public boolean isActual() { return index == WHOLE_COLLECTION || index >= 0 && index < getLength(); } /** * Returns the name of this node. Can be null. */ public abstract QName getName(); /** * Returns the value represented by the pointer before indexing. * So, if the node represents an element of a collection, this * method returns the collection itself. */ public abstract Object getBaseValue(); /** * Returns the object the pointer points to; does not convert it * to a "canonical" type. * * @deprecated 1.1 Please use getNode() */ public Object getNodeValue() { return getNode(); } /** * Returns the object the pointer points to; does not convert it * to a "canonical" type. Opens containers, properties etc and returns * the ultimate contents. */ public Object getNode() { return getValuePointer().getImmediateNode(); } public Object getRootNode() { if (rootNode == null) { rootNode = parent == null ? getImmediateNode() : parent.getRootNode(); } return rootNode; } /** * Returns the object the pointer points to; does not convert it * to a "canonical" type. */ public abstract Object getImmediateNode(); /** * Converts the value to the required type and changes the corresponding * object to that value. */ public abstract void setValue(Object value); /** * Compares two child NodePointers and returns a positive number, * zero or a positive number according to the order of the pointers. */ public abstract int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2); /** * Checks if this Pointer matches the supplied NodeTest. */ public boolean testNode(NodeTest test) { if (test == null) { return true; } if (test instanceof NodeNameTest) { if (isContainer()) { return false; } NodeNameTest nodeNameTest = (NodeNameTest) test; QName testName = nodeNameTest.getNodeName(); QName nodeName =

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> getName(); if (nodeName == null) { return false; } String testPrefix = testName.getPrefix(); String nodePrefix = nodeName.getPrefix(); if (!equalStrings(testPrefix, nodePrefix)) { String testNS = getNamespaceURI(testPrefix); String nodeNS = getNamespaceURI(nodePrefix); if (!equalStrings(testNS, nodeNS)) { return false; } } if (nodeNameTest.isWildcard()) { return true; } return testName.getName().equals(nodeName.getName()); } return test instanceof NodeTypeTest && ((NodeTypeTest) test).getNodeType() == Compiler.NODE_TYPE_NODE && isNode(); } private static boolean equalStrings(String s1, String s2) { return s1 == s2 || s1 != null && s1.equals(s2); } /** * Called directly by JXPathContext. Must create path and * set value. */ public NodePointer createPath(JXPathContext context, Object value) { setValue(value); return this; } /** * Remove the node of the object graph this pointer points to. */ public void remove() { // It is a no-op // System.err.println("REMOVING: " + asPath() + " " + getClass()); // printPointerChain(); } /** * Called by a child pointer when it needs to create a parent object. * Must create an object described by this pointer and return * a new pointer that properly describes the new object. */ public NodePointer createPath(JXPathContext context) { return this; } /** * Called by a child pointer if that child needs to assign the value * supplied in the createPath(context, value) call to a non-existent * node. This method may have to expand the collection in order to assign * the element. */ public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { throw new JXPathException("Cannot create an object for path " + asPath() + "/" + name + "[" + (index + 1) + "]" + ", operation is not allowed for this type of node");

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> * Locates a node by key and value. */ public Pointer getPointerByKey( JXPathContext context, String key, String value) { return context.getPointerByKey(key, value); } /** * Find a NodeSet by key/value. * @param context * @param key * @param value * @return NodeSet */ public NodeSet getNodeSetByKey(JXPathContext context, String key, Object value) { return context.getNodeSetByKey(key, value); } /** * Returns an XPath that maps to this Pointer. */ public String asPath() { // If the parent of this node is a container, it is responsible // for appended this node's part of the path. if (parent != null && parent.isContainer()) { return parent.asPath(); } StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); } if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } if (attribute) { buffer.append('@'); } buffer.append(getName()); if (index != WHOLE_COLLECTION && isCollection()) { buffer.append('[').append(index + 1).append(']'); } return buffer.toString(); } public Object clone() { try { NodePointer ptr = (NodePointer) super.clone(); if (parent != null) { ptr.parent = (NodePointer) parent.clone(); } return ptr; } catch (CloneNotSupportedException ex) { // Of course it is supported ex.printStackTrace(); } return null; } public String toString() { return asPath(); } public int compareTo(Object object) { if (object == this) { return 0; } // Let it throw a ClassCastException NodePointer pointer = (NodePointer) object; if (parent == pointer.parent) { return parent == null ? 0 : parent.compareChildNodePointers(this, pointer); } // Task 1: find the common parent int depth1 = 0; NodePointer p1 = this;

JxPath, 7

<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare > 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare >= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare < 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
<CHANGEE>
<CHANGES>
protected boolean evaluateCompare(int compare) {
return compare <= 0;
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.InfoSetUtil;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.SelfContext;
<CHANGEE>
<CHANGES>
public final Object computeValue(EvalContext context) {
return compute(args[0].computeValue(context), args[1]
.computeValue(context))? Boolean.TRUE : Boolean.FALSE;
}
<CHANGEE>
<CHANGES>
}
protected abstract boolean evaluateCompare(int compare);
private boolean compute(Object left, Object right) {
left = reduce(left);
right = reduce(right);
if (left instanceof InitialContext) {
((InitialContext) left).reset();
}
if (right instanceof InitialContext) {
((InitialContext) right).reset();
}
if (left instanceof Iterator && right instanceof Iterator) {
return findMatch((Iterator) left, (Iterator) right);
}
if (left instanceof Iterator) {
return containsMatch((Iterator) left, right);
}
if (right instanceof Iterator) {
return containsMatch((Iterator) right, left);
}
return evaluateCompare(compare(left, right));
}
private Object reduce(Object o) {
if (o instanceof SelfContext) {
o = ((EvalContext) o).getSingleNodePointer();
}
if (o instanceof Collection) {
o = ((Collection) o).iterator();
}
return o;
}
private boolean containsMatch(Iterator it, Object value) {
while (it.hasNext()) {
Object element = it.next();
if (evaluateCompare(compare(element, value))) {
return true;
}
}
return false;
}
private boolean findMatch(Iterator lit, Iterator rit) {
HashSet left = new HashSet();
while (lit.hasNext()) {
left.add(lit.next());
}
while (rit.hasNext()) {
if (containsMatch(left.iterator(), rit.next())) {
return true;
}
}
return false;
}
private int compare(Object l, Object r) {
double ld = InfoSetUtil.doubleValue(l);
double rd = InfoSetUtil.doubleValue(r);
return ld == rd? 0 : ld < rd? -1 : 1;
<CHANGEE>
<FILEE>
<FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; <CHANGES> import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; <CHANGEE> /** * Implementation of Expression for the operation "&gt;". * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } <CHANGES> public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return l > r ? Boolean.TRUE : Boolean.FALSE; <CHANGEE> } public String getSymbol() { return ">"; } } <FILEE> <FILEB> /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-<SCANS> HashSet parents1 = new HashSet(); while (p1 != null) { depth1++; p1 = p1.parent; if (p1 != null) { parents1.add(p1); } } boolean commonParentFound = false; int depth2 = 0; NodePointer p2 = pointer; while (p2 != null) { depth2++; p2 = p2.parent; if (parents1.contains(p2)) { commonParentFound = true; } } //nodes from different graphs are equal, else continue comparison: return commonParentFound ? compareNodePointers(this, depth1, pointer, depth2) : 0; } private int compareNodePointers( NodePointer p1, int depth1, NodePointer p2, int depth2) { if (depth1 < depth2) { int r = compareNodePointers(p1, depth1, p2.parent, depth2 - 1); return r == 0 ? -1 : r; } if (depth1 > depth2) { int r = compareNodePointers(p1.parent, depth1 - 1, p2, depth2); return r == 0 ? 1 : r; } //henceforth depth1 == depth2: if (p1 == p2 || p1 != null && p1.equals(p2)) { return 0; } if (depth1 == 1) { throw new JXPathException( "Cannot compare pointers that do not belong to the same tree: '" + p1 + "' and '" + p2 + "'"); } int r = compareNodePointers(p1.parent, depth1 - 1, p2.parent, depth2 - 1); return r == 0 ? p1.parent.compareChildNodePointers(p1, p2) : r; } /** * Print internal structure of a pointer for debugging */ public void printPointerChain() { printDeep(this, ""); } private static void printDeep(NodePointer pointer, String indent) { if (indent.length() == 0) { System.err.println( "POINTER: " + pointer